Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to bind to NATS JetStream by stream name. #2161

Closed
Jarema opened this issue Oct 7, 2022 · 8 comments
Closed

Add ability to bind to NATS JetStream by stream name. #2161

Jarema opened this issue Oct 7, 2022 · 8 comments
Labels
kind/enhancement New feature or request stale

Comments

@Jarema
Copy link
Contributor

Jarema commented Oct 7, 2022

Describe the feature

Currently, users of DAPR binding can subscribe to a stream only by looking up stream by matching subject.
I would like to add a config option to lookup stream by its name and then using it when calling Subscribe.
This is often simpler and more explicit and will additionaly allow fixing #2145 when user do not pass additional filter subject to the Consumer.

Let me know if you're ok with such approach, then I'll proceed with implementation.

Release Note

RELEASE NOTE:

@NickLarsenNZ
Copy link
Contributor

NickLarsenNZ commented Oct 10, 2022

Could you give an example of what the Dapr service code might look like?

Eg, would the Dapr topic then be the stream name?

@app.subscribe(pubsub_name='order-pub-sub', topic='orders')
def mytopic(event: v1.Event) -> None:
    data = json.loads(event.Data())
    logging.info('Subscriber received: ' + str(data))

Or do you mean the handlers would still discriminate on topic name, but the Component would force a particular stream?


Edit: I went back and looked at a comment you left me in #2145.

So the topic name would be empty in the handler/subscriber code. This might cause some confusion if it must be empty. It could still be handy allowing additional filtering.

Sorry if this is off topic here, just brainstorming:

So, for example, imagine a USERS stream that covers the subjects users.>.

And you have a Durable Consumer with Queue Group (so you don't miss messages when the app is down, and only one replica processes each message). This consumer will be used by multiple handlers, each doing their own bit of work.

You also might still want some sort of order (eg: user has to be added before changing the profile picture or something).

So it could look something like:

@app.subscribe(pubsub_name='users-pub-sub', topic='users.new')
def new_customer(event: v1.Event) -> None:
    data = json.loads(event.Data())
    logging.info('New user: ' + str(data))

@app.subscribe(pubsub_name='users-pub-sub', topic='customers.profile.image')
def new_customer(event: v1.Event) -> None:
    data = json.loads(event.Data())
    logging.info('Customer set or updated their profile picture: ' + str(data))

Would that still work? Two different topics (or filters?) from one stream, via one consumer? Or would it still need two separate consumers?

@Jarema
Copy link
Contributor Author

Jarema commented Oct 10, 2022

I was rather thinking of adding a new option to the Component config for NATS JetStream PubSub.

@dapr-bot
Copy link
Collaborator

dapr-bot commented Nov 9, 2022

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.

@dapr-bot dapr-bot added the stale label Nov 9, 2022
@dapr-bot
Copy link
Collaborator

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue, help wanted or triaged/resolved. Thank you for your contributions.

@yaron2 yaron2 reopened this Nov 16, 2022
@yaron2
Copy link
Member

yaron2 commented Nov 16, 2022

@Jarema will you be working on this?

@dapr-bot dapr-bot removed the stale label Nov 16, 2022
@NickLarsenNZ
Copy link
Contributor

NickLarsenNZ commented Nov 18, 2022

I was rather thinking of adding a new option to the Component config for NATS JetStream PubSub.

So that was solved in #2244 right?
Is it still possible to then write different handlers to filter the subject (topic in Dapr) like in my example above?

@dapr-bot
Copy link
Collaborator

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.

@dapr-bot dapr-bot added the stale label Dec 18, 2022
@dapr-bot
Copy link
Collaborator

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue, help wanted or triaged/resolved. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request stale
Projects
None yet
Development

No branches or pull requests

4 participants