0

Trying to convert an implementation using the .net library from using QueueClient.Create to the MessagingFactory.CreateQueueClient to be able to better control the BatchFlushInterval as well as to allowing the use of multiple factories over multiple connections to increase send throughput but running into roadblocks.

Right now we are creating QueueClients (they are maintained throughout the app) like this:

QueueClient.CreateFromConnectionString(address, queueName, ReceiveMode.PeekLock); // address is the connection string from the azure portal in the form of Endpoint=sb....

Trying to change it to creating a MessagingFactory in the class construtor that will be used to create the QueueClients:

messagingFactory = MessagingFactory.Create(address.Replace("Endpoint=",""),mfs);
// later on in another part of the class
messagingFactory.CreateQueueClient(queueName, ReceiveMode.PeekLock);
// error Endpoint not found.,

This throws the error Endpoint not found. If I don't replace the Endpoint= it won't even create the MessagingFactory. What is the proper way to handle this?

Notes:

  • address = Endpoint=sb://pmg-bus-mybus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=somekey

As an aside, we have a process that is trying to push as many messages as possible to a queue and others reading it. The readers seem to easily keep up with the sender and I'm trying to maximize the send rate.

lucuma
  • 18,247
  • 4
  • 66
  • 91
  • 1
    Same code works for me for connection string `Endpoint=sb://tadada.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=blablabla`. Is your different? – Mikhail Shilkov Apr 28 '18 at 17:43
  • When using the same format as yours, it throws: `System.UriFormatException: Invalid URI: The URI scheme is not valid. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at System.Uri..ctor(String uriString) at Microsoft.ServiceBus.Messaging.MessagingFactory.Create(String address, MessagingFactorySettings factorySettings) ....` – lucuma Apr 28 '18 at 17:53

1 Answers1

0

The address is the base address of namespace(sb://yournamespace.servicebus.windows.net/) you are connecting to. For more information, please refer to MessagingFactory. The following is the demo code :

 var Address = "sb://yournamespace.servicebus.windows.net/"; //base address of namespace you are connecting to.
 MessagingFactorySettings MsgFactorySettings = new MessagingFactorySettings
            {
                NetMessagingTransportSettings = new NetMessagingTransportSettings
                {
                    BatchFlushInterval = TimeSpan.FromSeconds(2)
                },
                TokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider("RootManageSharedAccessKey", "balabala..."),
                OperationTimeout = TimeSpan.FromSeconds(30)
            }; //specify operating timeout (optional)
 MessagingFactory messagingFactory = MessagingFactory.Create(Address, MsgFactorySettings);
 var queue =  messagingFactory.CreateQueueClient("queueName",ReceiveMode.PeekLock);
 var message = queue.Receive(TimeSpan.Zero);
Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47