Skip to content

Commit

Permalink
Add suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
aashikam committed Jun 21, 2023
1 parent 62beba5 commit 7c9f3c6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/nats-jetstream-pub/nats_jetstream_pub.bal
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ service / on new http:Listener(9092) {
// Initiate a NATS client passing the URL of the NATS broker.
nats:Client natsClient = check new (nats:DEFAULT_URL);

// Initiate the NATS JetStreamClient at the start of the service. This will be used
// Initiate the NATS `JetStreamClient` at the start of the service. This will be used
// throughout the lifetime of the service.
self.orderClient = check new (natsClient);
nats:StreamConfiguration config = {
Expand All @@ -28,7 +28,7 @@ service / on new http:Listener(9092) {
}

resource function post orders(Order newOrder) returns http:Accepted|error {
// Produces a message to the specified subject.
// Produce a message to the specified subject.
check self.orderClient->publishMessage({
subject: self.SUBJECT_NAME,
content: newOrder.toString().toBytes()
Expand Down
2 changes: 1 addition & 1 deletion examples/nats-jetstream-pub/nats_jetstream_pub.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NATS JetStream client - Publish message

The `nats:JetStreamClient` allows you to publish messages to a specific subject. To create a `nats:JetStreamClient`, you need to provide a valid instance of the `nats:Client`. Before publishing messages, you should call the addStream function to configure the stream. This function requires a `nats:JetStreamConfiguration` object with the values `name`, `subjects`, and `storageType`. To publish messages, you can use the `publishMessage` method, which takes the message content and subject as arguments. This method allows you to send messages that can be received by one or more subscribers.
The `nats:JetStreamClient` allows you to publish messages to a specific subject. To create a `nats:JetStreamClient`, you need to provide a valid instance of the `nats:Client`. Before publishing messages, you should call the `addStream` function to configure the stream. This function requires a `nats:JetStreamConfiguration` object with the `name`, `subjects`, and `storageType` values. To publish messages, you can use the `publishMessage` method, which takes the message content and subject as arguments. This method allows you to send messages that can be received by one or more subscribers.

::: code nats_jetstream_pub.bal :::

Expand Down
4 changes: 2 additions & 2 deletions examples/nats-jetstream-sub/nats_jestream_sub.bal
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ type Order readonly & record {
// Initiate a NATS client passing the URL of the NATS broker.
nats:Client natsClient = check new (nats:DEFAULT_URL);

// Initializes a NATS JetStream listener.
// Initialize a NATS JetStream listener.
listener nats:JetStreamListener subscription = new (natsClient);
const string SUBJECT_NAME = "orders";

@nats:StreamServiceConfig {
subject: SUBJECT_NAME,
autoAck: false
}
// Binds the consumer to listen to the messages published to the 'orders' subject.
// Bind the consumer to listen to the messages published to the 'orders' subject.
service nats:JetStreamService on subscription {
remote function onMessage(nats:JetStreamMessage message) returns error? {
string stringContent = check string:fromBytes(message.content);
Expand Down
2 changes: 1 addition & 1 deletion examples/nats-jetstream-sub/nats_jestream_sub.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NATS JetStream service - Consume message

The `nats:JetStreamService` listens to a specified subject for incoming messages. Whenever a publisher sends a message to that subject, any active service listening to it will receive the message. To create a `nats:JetStreamListener`, you need to provide an instance of the `nats:Client`. Once you have a `nats:JetStreamListener`, you can attach a `nats:JetStreamService` to it in order to listen to a specific subject and consume incoming messages. The subject to listen to can be either specified as the service path or provided in the `subject` field of the `nats:StreamServiceConfig`. This setup allows you to effectively listen to messages sent to a particular subject.
The `nats:JetStreamService` listens to a specified subject for incoming messages. Whenever a publisher sends a message to that subject, any active service listening to it will receive the message. You need to provide an instance of the `nats:Client` to create a `nats:JetStreamListener`. Once you have a `nats:JetStreamListener`, you can attach a `nats:JetStreamService` to it in order to listen to a specific subject and consume incoming messages. The subject to listen to can be either specified as the service path or provided in the `subject` field of the `nats:StreamServiceConfig`. This setup allows you to effectively listen to messages sent to a particular subject.

::: code nats_jestream_sub.bal :::

Expand Down

0 comments on commit 7c9f3c6

Please sign in to comment.