public ASBConsumerTests()
        {
            var command = new ASBTestCommand()
            {
                CommandValue  = "Do the things.",
                CommandNumber = 26
            };

            _correlationId = Guid.NewGuid();
            _channelName   = $"Consumer-Tests-{Guid.NewGuid()}".Truncate(50);
            _topicName     = $"Consumer-Tests-{Guid.NewGuid()}";
            var routingKey = new RoutingKey(_topicName);

            AzureServiceBusSubscription <ASBTestCommand> subscription = new(
                name : new SubscriptionName(_channelName),
                channelName : new ChannelName(_channelName),
                routingKey : routingKey
                );

            _contentType = "application/json";

            _message = new Message(
                new MessageHeader(command.Id, _topicName, MessageType.MT_COMMAND, _correlationId, contentType: _contentType),
                new MessageBody(JsonSerializer.Serialize(command, JsonSerialisationOptions.Options))
                );

            _subscriptionConfiguration = new AzureServiceBusSubscriptionConfiguration()
            {
                DeadLetteringOnMessageExpiration = true,
                DefaultMessageTimeToLive         = TimeSpan.FromDays(4),
                LockDuration     = TimeSpan.FromMinutes(3),
                MaxDeliveryCount = 7,
                SqlFilter        = "1=1"
            };

            var clientProvider = ASBCreds.ASBClientProvider;

            _administrationClient = new AdministrationClientWrapper(clientProvider);
            _administrationClient.CreateSubscription(_topicName, _channelName, _subscriptionConfiguration);

            _serviceBusClient = clientProvider.GetServiceBusClient();

            var channelFactory =
                new AzureServiceBusChannelFactory(new AzureServiceBusConsumerFactory(clientProvider, false));

            _channel = channelFactory.CreateChannel(subscription);

            _producerRegistry = new AzureServiceBusProducerRegistryFactory(
                clientProvider,
                new AzureServiceBusPublication[]
            {
                new AzureServiceBusPublication {
                    Topic = new RoutingKey(_topicName)
                }
            }
                )
                                .Create();
        }
示例#2
0
        public void When_the_timeout_is_below_400_ms_it_should_throw_an_exception()
        {
            var factory = new AzureServiceBusChannelFactory(new AzureServiceBusConsumerFactory(new AzureServiceBusConfiguration("someString")));

            var exception = Assert.Throws <ArgumentException>(() => factory.CreateChannel(new Connection(typeof(object), new ConnectionName("name"), new ChannelName("name"),
                                                                                                         new RoutingKey("name"),
                                                                                                         1, 1, 399)));

            Assert.That(exception.Message, Is.EqualTo("The minimum allowed timeout is 400 milliseconds"));
        }
        public ASBProducerTests()
        {
            _command = new ASBTestCommand()
            {
                CommandValue  = "Do the things.",
                CommandNumber = 26
            };

            _correlationId = Guid.NewGuid();
            var channelName = $"Producer-Send-Tests-{Guid.NewGuid()}".Truncate(50);

            _topicName = $"Producer-Send-Tests-{Guid.NewGuid()}";
            var routingKey = new RoutingKey(_topicName);

            AzureServiceBusSubscription <ASBTestCommand> subscription = new(
                name : new SubscriptionName(channelName),
                channelName : new ChannelName(channelName),
                routingKey : routingKey
                );

            _contentType = "application/json";

            _message = new Message(
                new MessageHeader(_command.Id, _topicName, MessageType.MT_COMMAND, _correlationId, contentType: _contentType),
                new MessageBody(JsonSerializer.Serialize(_command, JsonSerialisationOptions.Options))
                );

            var clientProvider = ASBCreds.ASBClientProvider;

            _administrationClient = new AdministrationClientWrapper(clientProvider);
            _administrationClient.CreateSubscription(_topicName, channelName, new AzureServiceBusSubscriptionConfiguration());

            var channelFactory =
                new AzureServiceBusChannelFactory(new AzureServiceBusConsumerFactory(clientProvider, false));

            _channel = channelFactory.CreateChannel(subscription);

            _producerRegistry = new AzureServiceBusProducerRegistryFactory(
                clientProvider,
                new AzureServiceBusPublication[]
            {
                new AzureServiceBusPublication {
                    Topic = new RoutingKey(_topicName)
                }
            }
                )
                                .Create();
        }