Azure Service Bus subscriber is needed to send the message to the topic - azure

I have tried to send a message to the topic of Azure Service Bus but it is not having any subscribers for now and it was showing there is no matching subscription found for it. So I have created a temporary subscriber for that and sent the message successfully.
So my question is it compulsory to having a subscriber to send the message to the topic??
Thanks for the help!

You do not have to have subscriptions under the topic to be able to publish messages. But in order to receive messages, subscriptions have to exist. Subscribers can come online later and fetch those events. Without subscriptions, subscribers will not get anything as the topic doesn't know what to retain and for whom.

Related

Read and Delete one or more message from azure service bus topic using logic app

Can we Read and Delete one or more message from azure service bus topic using logic app?
what does the Complete Message Action will do on a Logic App.
Read
You could read a message from the service bus. You could use one of the below connectors and triggers :
Get messages from a queue
Get messages from a topic
Or you could use one the following triggers which will get the message content to be read :
When a message is received in a queue (auto-complete)
When a message is received in a queue (peek-lock)
When a message is received in a topic subscription (auto-complete)
When a message is received in a topic subscription (peek-lock)
When one or more messages arrive in a queue (auto-complete) When one
or more messages arrive in a queue (peek-lock)
When one or more messages arrive in a topic (auto-complete)
When one or more messages arrive in a topic (peek-lock)
https://learn.microsoft.com/en-us/connectors/servicebus/#triggers
Complete Message Action (Also - Delete)
The operation completes a message in a queue or topic depending on which conector you use.
What does completes a message mean ?
When the receive operation is initiated, the message is locked by the receiving client. The message in the queue/topic remains undeleted. In case the message is not completed, the message would be available to be consumed again for the receiving clients after the lock expires.
So in short complete a message means that the message should be marked as processed and deleted from the queue or topic.
https://learn.microsoft.com/en-us/connectors/servicebus/#get-messages-from-a-queue-(peek-lock)
Update :
You could do something like below :
Explanation :
The above logic app gets triggered on a http request with the messages count that needs to be read.
Subsequently mentioned count of messages is retrieved from the service bus - topic combination and completed eventually.

How to Send message to Azure Service Bus Subscription Deadletter using Rest Api with deadletter Reason and Error Description?

I can't find an example of how to send a message to a Azure Service Bus Subscription DeadLetter using rest api. It appears that the suffix for the endpoint should be /Subscriptions//$deadletterqueue. However, I can't find an example of how to pass the deadletterReason, and the deadLetterErrorDescription. Is it be as simple as passing those values as message headers?
Messages are not sent directly to the dead-letter queue by the client code (REST API or any other SDK). Instead, messages are dead-lettered by the broker when MaxDeliveryCount is exceeded and no more attempts to process the message can be made. That's when the broker will move the message to the dead-letter queue with the reason.
Not that there are also less common reasons, such as the number of hops (forwarding), expired time-to-live, etc. MaxDeliveryCount is the most common scenario.
Microsoft documentation will help in addition to this post.

Messages sent to Topic are getting lost if no subscriptions are specified

In Azure Service Bus, if below is the sequence of events, then all's fine -
Create Topic
Create Subscriptions inside Topic
Send Messages to Topic
With above, the subscriptions are triggered when a message is sent. This is expected.
However, if we modify the above sequence like this
Create Topic
Send Messages to Topic
Create Subscriptions inside Topic
In this case, as messages are sent to a topic whilst no subscriptions were in place, when the subscriptions are indeed created, the previously sent messages don't show up in their list. Those messages are essentially 'lost'. Am not able to see those messages in Service Bus Explorer too.
The above sequence flow is relevant because we have detached publishers and subscribers, where the publisher just sends a message and subscribers, when they come online, create the subscriptions and handle them. The order in which the publisher and subscriber come online is not guaranteed.
How can I access/process messages sent to the topic before the subscriptions are created? What happens to such messages in the first place?
Thanks
It turns out that the above behavior is by design - if no subscriptions are there, then the message is lost.
To overcome this, Azure Service Bus provides a property on topic to enable the pre-filtering of messages before they are sent. So, if no filters/subscriptions are available, it'll throw an exception
Set the option on the Topic
namespaceManager.CreateTopicAsync(new TopicDescription(topicName)
{
EnableFilteringMessagesBeforePublishing = true
});
Whilst sending the message, check for exception
try
{
await topicClient.SendAsync(brokeredMessage);
}
catch (NoMatchingSubscriptionException ex)
{
// handle the exception, maybe send it to dead letter queue using DeadLetterAsync
}

Azure Service Bus Subscriber Deadletter

I've looked everywhere for information on this but can't seem to find what i'm looking for.
I've got an azure topic, with one subscription.
The handler for the subscription failed some messages, they've been put on the deadletter queue.
I can access the messages but i'm at a loss for how to restore them.
I don't want to create a copy of the message and send it to the topic. I specifically want to move it to the subscription queue it came from.
Is there any way to do this?
I don't know if this is possible.
What we mostly do to handle & resume messages, is to use the pattern of defering messages. If a handler fails a message, he can then defer the message and keep track of the messagesequence number (typically in a management / tracking database or component).
Whenever the message needs to be reprocessed (retried), a receiver can then specifically get that message (using the same defered message id) and process it again.

Send message directly to Subscription

Is it possible to send a message directly to a Subscription queue?
Scenario:
A message failed, dropped onto the deadletter, the message has been picked up manually using defer, cloned and needs to be sent to the queue it was first deadlettered on, but NOT the topic.
Can I send a message directly to a subscriber?
I've considered creating a separate retry queue per subscriber, where the handling service will also receive messages from but i'd rather not do this.
this is a similar question to the one you asked earlier: Azure Service Bus Subscriber Deadletter
this is not possible, as far as I know. the only thing you could do is to add an extra filter on every subscription that has something like SubscriptionName='SubscriptionA'. If you then want to send you deadlettered message to the specific subscription, you can add a property SubscriptionName to it, to achieve your goal. Take into account that you also have to make sure that in your original filter, you add a condition to indicate that the property SubscriptionName should not exist.
I agree however, that it would be a nice scenario to 'undeadletter' a message, so that it ends up again in his original subscription.

Resources