Giter Club home page Giter Club logo

Comments (18)

minghuaw avatar minghuaw commented on June 26, 2024 1

In Python I use to set the property "to" while sending message and on the Azure side I use to put filter on "to". How can I set the "to" property while sending the message to the topic?

There is a built-in method that allows you to set the to field for a message. https://docs.rs/azservicebus/latest/azservicebus/primitives/service_bus_message/struct.ServiceBusMessage.html#method.set_to

Something like this should work (not tested though)

let mut message = ServiceBusMessage::from("hello world");
message.set_to(String::from("<subscription name>"));
sender.send_message(message).await.unwrap();

from azservicebus.

minghuaw avatar minghuaw commented on June 26, 2024 1

I think all methods are documented on docs.rs (https://docs.rs/azservicebus/latest/azservicebus/index.html). The API mainly follows that of the dotnet SDK, so you could refer to the official tutorials written for the dotnet SDK and the look for the corresponding function in the rust SDK on docs.rs.

Just one more little help. How do I set content type of the message. Can you give an example?

This should do. https://docs.rs/azservicebus/latest/azservicebus/primitives/service_bus_message/struct.ServiceBusMessage.html#method.set_content_type

from azservicebus.

minghuaw avatar minghuaw commented on June 26, 2024 1

Is the below code snippet correct ?

let mut message = ServiceBusMessage::from("hello world"); message.set_to(String::from("")); message.set_content_type(String::from("application/json")); sender.send_message(message).await.unwrap();

Looks right to me. One more note, if you want an empty to field here, you could set it to None like

message.set_to(None);

That function takes anything that implements Into<Option<String>> and this includes String, Some(String) and None

from azservicebus.

horizondeep avatar horizondeep commented on June 26, 2024 1

I think all methods are documented on docs.rs (https://docs.rs/azservicebus/latest/azservicebus/index.html). The API mainly follows that of the dotnet SDK, so you could refer to the official tutorials written for the dotnet SDK and the look for the corresponding function in the rust SDK on docs.rs.

Just one more little help. How do I set content type of the message. Can you give an example?

This should do. https://docs.rs/azservicebus/latest/azservicebus/primitives/service_bus_message/struct.ServiceBusMessage.html#method.set_content_type

I will refer to this one. Thanks @minghuaw.

from azservicebus.

horizondeep avatar horizondeep commented on June 26, 2024

I tried many times but service bus subscription is not receiving message. My question is how a sender knows where to send the message (in which subscription of topic)
let mut sender = client
.create_sender(&topic_name, ServiceBusSenderOptions::default())
.await?;

from azservicebus.

minghuaw avatar minghuaw commented on June 26, 2024

This is not how the with_subscriber method should be used. That method is provided by the tracing crate for logging and the subscriber really means a log subscriber rather than your Service Bus subscription.

If you want to target a specific receiver, you should be using Service Bus Queue instead of Service Bus Topic as explained here (https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-queues-topics-subscriptions#topics-and-subscriptions).

A queue allows processing of a message by a single consumer. In contrast to queues, topics and subscriptions provide a one-to-many form of communication in a publish and subscribe pattern. It's useful for scaling to large numbers of recipients. Each published message is made available to each subscription registered with the topic. Publisher sends a message to a topic and one or more subscribers receive a copy of the message.

However, you could apply a filter on a subscription consumer, and you could modify certain properties of a message so that it can only pass through the filter of the desired consumer.

from azservicebus.

minghuaw avatar minghuaw commented on June 26, 2024

I will delete this issue once you consider it settled because you have pasted information (your connection string) that I consider confidential for you.

from azservicebus.

horizondeep avatar horizondeep commented on June 26, 2024

I will delete this issue once you consider it settled because you have pasted information (your connection string) that I consider confidential for you.

I used the dummy values.. :). Thanks.

from azservicebus.

horizondeep avatar horizondeep commented on June 26, 2024

This is not how the with_subscriber method should be used. That method is provided by the tracing crate for logging and the subscriber really means a log subscriber rather than your Service Bus subscription.

If you want to target a specific receiver, you should be using Service Bus Queue instead of Service Bus Topic as explained here (https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-queues-topics-subscriptions#topics-and-subscriptions).

A queue allows processing of a message by a single consumer. In contrast to queues, topics and subscriptions provide a one-to-many form of communication in a publish and subscribe pattern. It's useful for scaling to large numbers of recipients. Each published message is made available to each subscription registered with the topic. Publisher sends a message to a topic and one or more subscribers receive a copy of the message.

However, you could apply a filter on a subscription consumer, and you could modify certain properties of a message so that it can only pass through the filter of the desired consumer.

So I have a service bus "topic" under which I have "subscription". How do I send a message to that particular subscription?

from azservicebus.

horizondeep avatar horizondeep commented on June 26, 2024

Azure/azure-service-bus#366 . This diagram depicts the correct illustration.

from azservicebus.

minghuaw avatar minghuaw commented on June 26, 2024

So I have a service bus "topic" under which I have "subscription". How do I send a message to that particular subscription?

You send to the topic, and all subscriptions under that topic will get a copy of that message. You should use the topic name when you create the sender and use both the topic and subscription names when you create the receiver.

If you are looking for a one-to-one mapping, a queue is what you are after not topic

from azservicebus.

minghuaw avatar minghuaw commented on June 26, 2024

Azure/azure-service-bus#366 . This diagram depicts the correct illustration.

As shown in the diagram you quoted. You don't send to subscription directly. You send to the topic (by creating a sender to the topic), then all subscriptions under that topic will get the same message. Message filtering is handled on the subscription side, you could add filter rules on azure portal or in code following this example (https://github.com/minghuaw/azservicebus/blob/main/examples/manage_rules.rs)

from azservicebus.

minghuaw avatar minghuaw commented on June 26, 2024

The difference between queue, and topic/subscription is better explained here (https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-queues-topics-subscriptions)

from azservicebus.

horizondeep avatar horizondeep commented on June 26, 2024

Azure/azure-service-bus#366 . This diagram depicts the correct illustration.

As shown in the diagram you quoted. You don't send to subscription directly. You send to the topic (by creating a sender to the topic), then all subscriptions under that topic will get the same message. Message filtering is handled on the subscription side, you could add filter rules on azure portal or in code following this example (https://github.com/minghuaw/azservicebus/blob/main/examples/manage_rules.rs)

Thanks for the explanation. Yes I do have a filter on subscription to receive/filter message, but still not receiving message. Below are the system properties key in Azure to filter out the message: 1. correlationID 2.contenType 3. label/subject 4. messageId 5.replyto 6.replytoSessionId 7.sessionId 8. to

In Python I use to set the property "to" while sending message and on the Azure side I use to put filter on "to". How can I set the "to" property while sending the message to the topic?

from azservicebus.

horizondeep avatar horizondeep commented on June 26, 2024

In Python I use to set the property "to" while sending message and on the Azure side I use to put filter on "to". How can I set the "to" property while sending the message to the topic?

There is a built-in method that allows you to set the to field for a message. https://docs.rs/azservicebus/latest/azservicebus/primitives/service_bus_message/struct.ServiceBusMessage.html#method.set_to

Something like this should work (not tested though)

let mut message = ServiceBusMessage::from("hello world");
message.set_to(String::from("<subscription name>"));
sender.send_message(message).await.unwrap();

Thanks @minghuaw. This solved my problem. Also thanks for the prompt replies.

from azservicebus.

horizondeep avatar horizondeep commented on June 26, 2024

Just one more little help. How do I set content type of the message. Can you give an example?

from azservicebus.

horizondeep avatar horizondeep commented on June 26, 2024

Is the below code snippet correct ?

let mut message = ServiceBusMessage::from("hello world");
message.set_to(String::from(""));
message.set_content_type(String::from("application/json"));
sender.send_message(message).await.unwrap();

from azservicebus.

horizondeep avatar horizondeep commented on June 26, 2024

set_content_type

Got it thanks.

from azservicebus.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.