Skip to content

Commit

Permalink
Thu May 2 01:29:50 PM IDT 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
g41797 committed May 2, 2024
1 parent 89e83c4 commit b067bc7
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"autoload-dev": {
"psr-4": {
"Yiisoft\\Queue\\Redis\\Nats\\": "testsnats"
"Yiisoft\\Queue\\Nats\\": "testsnats"
}
},
"extra": {
Expand Down
75 changes: 75 additions & 0 deletions notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Nats
https://nats.io/

Nats JS(jetstream)
https://docs.nats.io/nats-concepts/jetstream
https://docs.nats.io/using-nats/developer/develop_jetstream
https://docs.nats.io/nats-concepts/core-nats/queue#stream-as-a-queue

JetStream wire API Reference
https://docs.nats.io/reference/reference-protocols/nats_api_reference

Shemas
https://github.com/nats-io/jsm.go/tree/main/schema_source/jetstream/api/v1

JetStream Model Deep Dive
https://docs.nats.io/using-nats/developer/develop_jetstream/model_deep_dive

Pedantic mode
https://docs.nats.io/using-nats/developer/connecting/misc#turn-on-pedantic-mode

Using NATS streaming for event sourcing with snapshots
https://groups.google.com/g/natsio/c/OetiXggcFHk

Go JetStream Simplified Client
https://github.com/nats-io/nats.go/tree/main/jetstream#jetstream-simplified-client

Nats JS client for php
https://github.com/basis-company/nats.php

Description of usage
https://github.com/basis-company/nats.php/issues/59#issuecomment-1907919039

Ephemeral Consumer life cycle
https://natsio.slack.com/archives/CM3T6T7JQ/p1711275996676309
https://natsio.slack.com/archives/CM3T6T7JQ/p1711278584957209?thread_ts=1711275996.676309&cid=CM3T6T7JQ

Nats streaming as task queue
https://github.com/nats-io/stan.js/issues/49

Nats articles
https://www.byronruth.com/tag/series/

NATS and Docker
https://docs.nats.io/running-a-nats-service/nats_docker

RoadRunner Jobs
https://docs.roadrunner.dev/queues-and-jobs/overview-queues

Nats Jobs
https://docs.roadrunner.dev/queues-and-jobs/nats
https://github.com/roadrunner-server/nats/tree/master/natsjobs

Beanstalk Jobs
https://docs.roadrunner.dev/queues-and-jobs/beanstalk

Allowed number of consumers for JS as Queue (WorkQueuePolicy)
https://natsio.slack.com/archives/CM3T6T7JQ/p1712153925255479

JetStream Java tutorial
https://nats.io/blog/hello-world-java-client/

JetStream stream creation in Java
https://nats.io/blog/jetstream-java-client-01-stream-create/

JetStream publishing in Java
https://nats.io/blog/jetstream-java-client-02-publish/

Consumers in Java
https://nats.io/blog/jetstream-java-client-03-consume/

Push consumers in Java
https://nats.io/blog/jetstream-java-client-04-push-subscribe/#jetstream-push-consumers-with-the-natsio-java-library

Pull consumers in Java
https://nats.io/blog/jetstream-java-client-05-pull-subscribe/#jetstream-pull-consumers-with-the-natsio-java-library
Empty file added srcnats/.gitkeep
Empty file.
18 changes: 18 additions & 0 deletions srcnats/Exception/DelayNotImplementedNatsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Yiisoft\Queue\Nats\Exception;

use Yiisoft\FriendlyException\FriendlyExceptionInterface;

class DelayNotImplementedNatsException extends \RuntimeException implements FriendlyExceptionInterface
{
public function getName(): string
{
return 'Delay not implemented';
}

public function getSolution(): ?string
{
return 'Use 0 as delay value';
}
}
21 changes: 21 additions & 0 deletions srcnats/Exception/NotConnectedNatsException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Queue\Nats\Exception;

use Yiisoft\FriendlyException\FriendlyExceptionInterface;

class NotConnectedNatsException extends \RuntimeException implements FriendlyExceptionInterface
{
public function getName(): string
{
return 'Not connected to Nats.';
}

public function getSolution(): ?string
{
return 'Check your Nats configuration and run nats->connect() before using it.';
}
}

46 changes: 46 additions & 0 deletions srcnats/Message/Message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace Yiisoft\Queue\Nats\Message;

use Yiisoft\Queue\Message\MessageInterface;
use Yiisoft\Queue\Nats\Exception\DelayNotImplementedNatsException;

class Message implements MessageInterface
{
public function __construct(
private string $handlerName,
private mixed $data,
private array $metadata,
private int $delay = 0 //delay in seconds
) {
if (0 != $delay) {
throw new DelayNotImplementedNatsException();
}
}

public function withDelay(int $delay): self
{
if (0 != $delay) {
throw new DelayNotImplementedNatsException();
}

$message = clone $this;

return $message;
}

public function getHandlerName(): string
{
return $this->handlerName;
}

public function getData(): mixed
{
return $this->data;
}

public function getMetadata(): array
{
return $this->metadata;
}
}

0 comments on commit b067bc7

Please sign in to comment.