Reputation: 395
So I'm currently trying to get a Azure Bus Service to work in which I create a Queue and then a message is put on the queue and then received else where, and some code is ran using the data the message passed through. I've got everything set up and working, as in I can send a message and received it, however with some issues. Whilst researching I've discovered what seems to be two different methodologies to completing the same task.
Firstly:
Create a message:
public static void CreateMessage(string data, [ServiceBus("QueueName")] out string output)
{
output = data;
}
Receive a Message:
public static void ProcessMessage([ServiceBusTrigger("QueueName")] string data)
{
//Do something with data
}
Note: I am trying to use this methodology and whilst a message is being received, data is null when received. Any help with this would be much appreciated.
Secondly:
Create a message:
var client = QueueClient.CreateFromConnectionString(connectionString, queueName);
var message = new BrokeredMessage("This is a test message!");
client.Send(message);
Receive a message:
var queueName = "QueueName";
var client = QueueClient.CreateFromConnectionString(connectionString, queueName);
client.OnMessage(message =>
{
//do something with data
});
So a couple of questions.
1.What is the difference in these two methodologies, and where should each be applied?
2.Whilst I'm using the first methodology to try and simply send a string, can anyone tell me why 'data' is coming through as null, even though the message is received.
Upvotes: 0
Views: 1061
Reputation: 3293
1.What is the difference in these two methodologies, and where should each be applied?
The first methodology uses Azure Webjob SDK to create a message and receive the message. The second methodology uses Azure .Net library. We can use webjob to create scheduler background task very easily. The WebJobs SDK has a binding and trigger system which works with Microsoft Azure Storage Blobs, Queues and Tables as well as Service Bus Queues. If you choose .Net library, and want to use it to do some trigger job, we need to write our logic code.
data is null when received
Do you mean that the method ProcessMessage is triggered, however the value of the data is null? From my test, it shows the value correctly. I use a QueueTrigger to send a message to service bus, then receive this message in ServiceBusTrigger. The following is my tested code.
Please check your code carefully. If possible, please delete your sensitive connection string, upload to onedrive, then share the link here. It will better for us to reproduce your issue.
Upvotes: 3