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

Unable to add multiple subscriptions #81

Closed
NickLarsenNZ opened this issue Sep 30, 2022 · 3 comments
Closed

Unable to add multiple subscriptions #81

NickLarsenNZ opened this issue Sep 30, 2022 · 3 comments

Comments

@NickLarsenNZ
Copy link
Contributor

NickLarsenNZ commented Sep 30, 2022

There is currently no way to add additional subscriptions. ListTopicSubscriptionResponse::topic(...) is hard coded to a vector of one subscription: https://docs.rs/dapr/0.9.0/src/dapr/appcallback.rs.html#42

Originally posted by @NickLarsenNZ in #80 (comment)


Other SDKs seem to be able to do it (I have seen it in action with .Net), for example dapr/python-sdk:

https://github.com/dapr/python-sdk/blob/1aab2cb1e06b32899183a285eab5c975408d05b2/ext/dapr-ext-grpc/dapr/ext/grpc/app.py#L137-L140

@NickLarsenNZ
Copy link
Contributor Author

NickLarsenNZ commented Sep 30, 2022

Actually, it looks like I can if I avoid using the topic method, and instead build the ListTopicSubscriptionsResponse struct from scratch like so:

    async fn list_topic_subscriptions(
        &self,
        _request: Request<()>,
    ) -> Result<Response<ListTopicSubscriptionsResponse>, Status> {
        // This commented out section only allows a single subscription with no ability to extend.
        // let list_subscriptions =
        //     ListTopicSubscriptionsResponse::topic(self.pubsub_name.clone(), self.topic.clone());


        let empty_metadata = None;

        let list_subscriptions = ListTopicSubscriptionsResponse {
            subscriptions: vec![
                TopicSubscription::new("pubsub".to_owned(), "a".to_owned(), empty_metadata.clone()),
                TopicSubscription::new("pubsub".to_owned(), "b".to_owned(), empty_metadata.clone()),
            ],
        };

        Ok(Response::new(list_subscriptions))
    }

This appears to work, based on the daprd logs:

time="2022-09-30T22:56:55.85175101Z" level=info msg="app is subscribed to the following topics: [a b] through pubsub=pubsub" app_id=job-scheduler instance=a1f7de26e44f scope=dapr.runtime type=log ver=edge

@NickLarsenNZ
Copy link
Contributor Author

NickLarsenNZ commented Sep 30, 2022

It does appear to silently fail if you create two instances of the Dapr AppCallbackServers, like this which I had originally tried:

    Server::builder()
        .trace_fn(|_| tracing::info_span!("tonic server"))
        .add_service(AppCallbackServer::new(job_runner::JobRunner::new(
            pubsub.as_str(),
            topic.as_str(),
        )))
        .add_service(AppCallbackServer::new(job_runner::JobRunner::new(
            pubsub.as_str(),
            "another.topic",
        )))
        .serve(addr)
        .await?;

@mikeee
Copy link
Member

mikeee commented Mar 20, 2024

#87 (comment)
I think this can be addressed for now with the above merged. Let me know any thoughts otherwise :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants