This is an automated email from the ASF dual-hosted git repository.
blankensteiner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-dotpulsar.git
The following commit(s) were added to refs/heads/master by this push:
new 3ca870e modified the "hello world" to fix first run issue (#110)
3ca870e is described below
commit 3ca870ed6c4a67f54fc54849287f0101a1a27ab1
Author: Joshua Lapinski <[email protected]>
AuthorDate: Fri Sep 30 14:33:17 2022 -0700
modified the "hello world" to fix first run issue (#110)
* modified the "hello world" to fix first run issue
the current "hello world" will not show a consumed message the very first
time it is run. On subsequent runs, it will work, but it isn't entirely clear
from the code alone why it works on subsequent runs.
I don't entirely understand why the order matters here, but I believe it
isn't showing the consumed message on the first run because the subscription is
created after the producer sends a message. It seems that by default, a new
subscription will not consume messages that are created before it.
An alternative solution would be to create the consumer with the
"InitialPosition" option set to Earliest
(".InitialPosition(SubscriptionInitialPosition.Earliest"), but I think it's
preferable to minimize optional configuration in a hello world like this.
* Revised "Hello World" update
Per feedback, revised the "Hello World" code to use the optional
"InitialPosition" configuration setting on the consumer.
---
README.md | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index d031189..56a860b 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ Have a look at the [changelog](CHANGELOG.md).
## Getting Started
-Let's take a look at a "Hello world" example, where we first produce a message
and then consume it.
+Let's take a look at a "Hello world" example, where we first produce a message
and then consume it. Note that the topic and subscription will be created if
they don't exist.
First, we need a Pulsar setup. Have a look
[here](https://pulsar.apache.org/docs/en/standalone-docker/) to see how to
setup a local standalone Pulsar instance.
Install the NuGet package
[DotPulsar](https://www.nuget.org/packages/DotPulsar/) and copy/paste the code
below (you will be needing using declarations for 'DotPulsar' and
'DotPulsar.Extensions').
@@ -32,6 +32,7 @@ _ = await producer.Send("Hello World"); // Send a message and
ignore the returne
await using var consumer = client.NewConsumer(Schema.String)
.SubscriptionName("MySubscription")
.Topic(myTopic)
+
.InitialPosition(SubscriptionInitialPosition.Earliest)
.Create();
await foreach (var message in consumer.Messages())