I am currently working on a project that depends on .net 4.5, which I am why forced to use Microsoft.Servicebus - and thus message factory
Creating a messagefactory object, doesn't seem to be problem, but creating the message sender seem to be the issue here.
I am not sure what the entity path for my azure message queue is, and don't know how I should look it up?
I initialized my message factory as such;
public Microsoft.ServiceBus.Messaging.MessagingFactory client = Microsoft.ServiceBus.Messaging.MessagingFactory.CreateFromConnectionString(ServiceBusConnectString);
Where servicebusconnectionstring, is the primary conenctionstring extracted from the azure queue, or by following this guide: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues#1-create-a-namespace-using-the-azure-portal
The message sender is created as such:
Microsoft.ServiceBus.Messaging.MessageSender sender = client.CreateMessageSender(destinationQueue,queueName);
Again destionationQueue, and queueName are strings, which are defined from azure?
The message is to be send is created as such:
Microsoft.ServiceBus.Messaging.BrokeredMessage message = new Microsoft.ServiceBus.Messaging.BrokeredMessage(e.ToXml());
e
is just an object, which has publich function which can convert it to an xml string.
Here is where I send the message:
try
{
IntegrationLogger.Write(LogLevel.Verbose, "Sending message to azure");
sender.Send(message);
}
catch(System.Exception ex)
{
if(ex is System.TimeoutException)
{
IntegrationLogger.Write(LogLevel.Error, "Timeout exeption");
}
if (ex is System.ArgumentException)
{
IntegrationLogger.Write(LogLevel.Error, "Message is empty");
}
}
IntegrationLogger
is a log function I use - and the last message being logged is "Sending message to azure", meaning somethng goes wrong when I send it.
even catch does not catch the exception?..
What could be the problem here?
Am I using the sender incorrectly?
I am not sure what the enity path for my azure message queue is, and don't know how i should look it up?
If we want to create queue MessageSender, we could use following code.
var sender = client.CreateMessageSender(queueName);
We also could use queueclient to send and receive the broker messsage.
var client = QueueClient.CreateFromConnectionString("servicebus connection string", queueName);
// how to send message
var sendMessage = new BrokeredMessage(data);
client.Send(sendMessage);
//how to receive message
client.OnMessage(message =>
{
var dataInfo = message.GetBody<T>();
});
IntegrationLogger is a log function I use - and the last message being logged is "Sending message to azure", meaning somethng goes wrong when I send it. even catch does not catch the exepetion?..
In your case I recommand that you could add the log info to check whether there is any exception during send message.
try
{
IntegrationLogger.Write(LogLevel.Verbose, "Sending message to azure");
sender.Send(message);
//add log
IntegrationLogger.Write(LogLevel.Verbose, "Send message successfully");
}