Beispiel #1
0
        public void CreateMessageReceiver_ReturnsExpectedReceiver()
        {
            MessagingFactory factory  = _provider.CreateMessagingFactory("test");
            MessageReceiver  receiver = _provider.CreateMessageReceiver(factory, "test");

            Assert.Equal("test", receiver.Path);

            _config.PrefetchCount = 100;
            receiver = _provider.CreateMessageReceiver(factory, "test");
            Assert.Equal(100, receiver.PrefetchCount);
        }
Beispiel #2
0
        public void CreateMessageProcessor_ReturnsExpectedReceiver()
        {
            string defaultConnection = "Endpoint=sb://default.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abc123=";
            var    config            = new ServiceBusConfiguration
            {
                ConnectionString = defaultConnection
            };
            var provider = new MessagingProvider(config);
            var receiver = provider.CreateMessageReceiver("entityPath", defaultConnection);

            Assert.Equal("entityPath", receiver.Path);

            config.PrefetchCount = 100;
            receiver             = provider.CreateMessageReceiver("entityPath1", defaultConnection);
            Assert.Equal(100, receiver.PrefetchCount);
        }
        public Task StartAsync(CancellationToken cancellationToken)
        {
            ThrowIfDisposed();

            if (_started)
            {
                throw new InvalidOperationException("The listener has already been started.");
            }

            if (_isSessionsEnabled)
            {
                _clientEntity = _messagingProvider.CreateClientEntity(_entityPath, _serviceBusAccount.ConnectionString);

                if (_clientEntity is QueueClient queueClient)
                {
                    queueClient.RegisterSessionHandler(ProcessSessionMessageAsync, _serviceBusOptions.SessionHandlerOptions);
                }
                else
                {
                    SubscriptionClient subscriptionClient = _clientEntity as SubscriptionClient;
                    subscriptionClient.RegisterSessionHandler(ProcessSessionMessageAsync, _serviceBusOptions.SessionHandlerOptions);
                }
            }
            else
            {
                _receiver = _messagingProvider.CreateMessageReceiver(_entityPath, _serviceBusAccount.ConnectionString);
                _receiver.RegisterMessageHandler(ProcessMessageAsync, _serviceBusOptions.MessageHandlerOptions);
            }
            _started = true;

            return(Task.CompletedTask);
        }
Beispiel #4
0
        private Task StartAsyncCore(CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            _receiver = _messagingProvider.CreateMessageReceiver(_messagingFactory, _entityPath);
            _receiver.OnMessageAsync(ProcessMessageAsync, _messageProcessor.MessageOptions);

            return(Task.FromResult(0));
        }
Beispiel #5
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            ThrowIfDisposed();

            if (_receiver != null)
            {
                throw new InvalidOperationException("The listener has already been started.");
            }

            _receiver = _messagingProvider.CreateMessageReceiver(_entityPath, _serviceBusAccount.ConnectionString);
            _receiver.RegisterMessageHandler(ProcessMessageAsync, _messageProcessor.MessageOptions);

            return(Task.CompletedTask);
        }
 private Lazy <MessageReceiver> CreateMessageReceiver()
 {
     return(new Lazy <MessageReceiver>(() => _messagingProvider.CreateMessageReceiver(_entityPath, _serviceBusAccount.ConnectionString)));
 }