How to implement MSMQ Receive as like Azure Queue? - azure

We are migrating application from Azure to On Prem which has Queue option and decided to implement MSMQ as like Azure Queue but some of the options are not exactly available in MSMQ queue.
AddMessage & Peekmessage in Azure Queue and Send & Peek in MSMQ are Same
GetMessage in Azure Queue is used to get the next queue message and we can set the visibility time to avoid others to process the same queue.
Receive in MSMQ to get the latest message and at the same time it automatically deleted from the queue.
DeleteMessage in Azure Queue, everything is fine after fetching the message from queue then we have to delete the message using DeletMessage but we don't have this option available in MSMQ.
Updatemessage in Azure Queue is used to update the message but we dont have this option in MSMQ.
Please help me, How to implement the GetMessage as like we are using in Azure Queue.

I don't think that there's an easy way to do that.
To delete and get message, you just need to dequeue it and proccess it.
You can do that using method ReceiveById:
https://msdn.microsoft.com/en-us/library/0t877y0k(v=vs.110).aspx

Related

Write a listener application for Azure Service Bus Queue

I need to have a listener app in .NET Core which will continuously look into new messages in Azure Service Bus Queue. I've tried so far with different approaches, but only able to read messages from ASB queue which are already published to queue before my listener application has started consuming. But once all the existing messages are processed and then the listener is not able to read any new messages from ASB queue.
I'm trying to figure out whether there is any method in the namespace "Azure.Messaging.ServiceBus" which will continuously pull messages from ASB queue.
I do not want to create a WHILE loop or a long running Task.
Any help is appreciated.
There are 4 ways to create an "Azure Service Bus Queue". This could be the long procedure to understand. To make it precise, I am attaching the links to follow for different methods of creation.
ARM Template : https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-resource-manager-namespace-queue
Powershell: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quickstart-powershell
Azure CLI: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quickstart-cli
Azure Portal: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quickstart-portal
The Suitable answer for the requirement:
The receive modes are two types.
Receive and Delete
Peek lock
We can receive the message and pull it to read using Azure.Messaging.ServiceBus as required. Using the namespaces and utilizing the services of Azure.Messaging.ServiceBus

Azure storage account queue get new messages arrived (Ideally Logic App)

I am trying to design a logic app where when a message arrives or is received by poison queue(located in azure storage account) it posts to slack channel.
I know how to do the slack part and I can get the trigger to fire on queues located in my service bus resource because azure logic apps includes triggers for that.
However, I don't see azure logic app triggers for queues in the storage account for when a message arrives or is received in a queue.
My question is: Is there a trigger or other process that I can tap into when messages arrives in those storage account queues? If not, what is the best way to achieve being able to get this data (Message and Message Content) when it arrives in my poison queue in the storage account then take that info and throw that info into the slack channel?
Is there a trigger (for logic app) on the “storage account” queues that can be fired when a message is received?(I see length, and scan all messages in queue)
I have found triggers for this on the “service bus” queues.
These are the trigger options I have found for "service bus queues": https://i.stack.imgur.com/nS0nu.png
These are the trigger options I have found for "storage account queues": https://i.stack.imgur.com/AqxB4.png
Ideally, I just want to configure a simple logic app for when queue messages arrive in poison queue in storage account then take info to slack, i know how to put info in slack via logic app in service bus queue but haven't been able to figure out how to set up the action to pass the message to slack because I can't figure out how to do it when a message is recieved, i can set it as a job and grab length of queue and all items in queue, but not fire on arrival because I can't find a trigger for that.
If I can't figure this out or if at can't be done, I am probably just going to initiate the logic app with and Azure Queue storage trigger on an Azure function, this seems to be how MS wants us to do it anyway.
https://learn.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to
ctrl+f "Binding reference information" then see sub heading "Usage: The types you can bind to and information about how the binding works. For example: polling algorithm, poison queue processing."
thanks again for the input folks, appreciate ya!
According to some test, it works fine in my side with "When a specified number of messages are in a given queue" trigger. When I add a message to my queue which named myqueue-items-poison, the logic app was triggered success.
So please check if you have configured the trigger correctly.
Please check if you set the interval of the trigger too long, I set it with 1 minute.

How to peek recently sent messages into Service bus queue?

I am sending messages from my custom application to servicebus. And recently I have added some messages for testing purposes. But later I realized that I have picked the wrong Queue. Now I don't want the Test messages to be in this queue. Is there any possible way to delete those recently added test messages from my queue?
As mentioned by Pedro in his comment you can use service bus explorer: https://github.com/paolosalvatori/ServiceBusExplorer to peek and delete the message from the queue. Alternatively, you can call the service bus REST API or write your own code to consume that message.
As an alternative you can use Service Bus Cloud Explorer which runs in the browser with logged-in user Azure account by default and have a delete and a purge functionality.
Keep in mind that it will take time to clear up queues or subscriptions. More messages it needs to delete; the more time it would take.

How to manually send message to service bus dead letter queue in Azure Function?

The Azure Service Bus Queue triggered function would perform a default policy for sending message into the dead letter queue if message is poisoned. However, is there anyway that we could manually send the message to dead letter queue? There are couple of times that we wouldn't want Azure Function to perform its default policy due to some kind of internal or business exception, we would like to bind additional information to our message and manually send it to our Azure Service Bus Deadletter Queue.
In a previous version where it's using BrokeredMessage object, there is a method called
BrokeredMessage msg;
msg.DeadLetter();
However, in the most recent Functino 2.X, where it's using the Message object, that doesn't have this method somehow...
With Functions 2.0 you use the .NET Standard Service Bus client. Message no longer has operations such as dead-lettering. Instead, you need to add an additional parameter of MessageReceiver type to be able to use DeadletterAsync() method it provides. You can find an example of how to use message receiver in my post.
From my understanding there is no straight forward way but the following steps could help:
Go to the queues overview in the Azure portal and enable dead-lettering on message expiration on your subscription/queue.
Set TimeToLive on your message to say few seconds. (I did while creating a test queue, in the creation it is simple)
Push the message to your subscription.
Within few seconds you will have all your messages in dead-letter queue.
//(Provided no app is reading from the subscription during those seconds)
Finished

Azure web job, service bus trigger not triggered for old messages available in the queue

I have implemented the azure web job to consume messages from azure service bus. Service bus trigger works fine for new messages arrived to service bus but its not picking up the messages that were already available on the service bus before service start. Is there any configuration to get existing messages to the web job?
Due to some reason, some messages got abandon. What are the best ways to reprocess these messages.
If you get messsage and can't complete or abandon it 10 times(default), the message will go dead queue.
You can get dead queue like this.
_messagingFactory.CreateQueueClient(QueueClient.FormatDeadLetterPath(QueueDescription.Path), ReceiveMode.PeekLock);

Resources