public ControlBusSenderFactoryTests()
        {
            _fakeOutboxSync = A.Fake <IAmAnOutboxSync <Message> >();
            s_fakeGateway   = A.Fake <IAmAMessageProducerSync>();

            s_senderFactory = new ControlBusSenderFactory();
        }
Beispiel #2
0
        public void Repost(List <string> messageIds, IAmAnOutboxSync <Message> outBox, IAmAMessageProducerSync messageProducerSync)
        {
            var foundMessages = GetMessagesFromOutBox(outBox, messageIds);

            foreach (var foundMessage in foundMessages)
            {
                messageProducerSync.Send(foundMessage);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Gets the selected messages from the store
        /// </summary>
        /// <param name="outBox">The store to retrieve from</param>
        /// <param name="messageIds">The messages to retrieve</param>
        /// <returns></returns>
        private static IEnumerable <Message> GetMessagesFromOutBox(IAmAnOutboxSync <Message> outBox, IReadOnlyCollection <string> messageIds)
        {
            IEnumerable <Message> foundMessages = messageIds
                                                  .Select(messageId => outBox.Get(Guid.Parse(messageId)))
                                                  .Where(fm => fm != null)
                                                  .ToList();

            if (foundMessages.Count() < messageIds.Count)
            {
                throw new IndexOutOfRangeException("Cannot find messages " +
                                                   string.Join(",", messageIds.Where(id => foundMessages.All(fm => fm.Id.ToString() != id.ToString())).ToArray()));
            }
            return(foundMessages);
        }
        public ControlBusSenderPostMessageAsyncTests()
        {
            _myCommand.Value = "Hello World";

            _outbox = new InMemoryOutbox();
            _fakeMessageProducerWithPublishConfirmation = new FakeMessageProducerWithPublishConfirmation();

            const string topic = "MyCommand";

            _message = new Message(
                new MessageHeader(_myCommand.Id, topic, MessageType.MT_COMMAND),
                new MessageBody(JsonSerializer.Serialize(_myCommand, JsonSerialisationOptions.Options))
                );

            var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory((_) => new MyCommandMessageMapper()));

            messageMapperRegistry.Register <MyCommand, MyCommandMessageMapper>();

            var retryPolicy = Policy
                              .Handle <Exception>()
                              .RetryAsync();

            var circuitBreakerPolicy = Policy
                                       .Handle <Exception>()
                                       .CircuitBreakerAsync(1, TimeSpan.FromMilliseconds(1));

            _commandProcessor = new CommandProcessor(
                new InMemoryRequestContextFactory(),
                new PolicyRegistry {
                { CommandProcessor.RETRYPOLICYASYNC, retryPolicy }, { CommandProcessor.CIRCUITBREAKERASYNC, circuitBreakerPolicy }
            },
                messageMapperRegistry,
                _outbox,
                new ProducerRegistry(new Dictionary <string, IAmAMessageProducer>()
            {
                { topic, _fakeMessageProducerWithPublishConfirmation },
            }));

            _controlBusSender = new ControlBusSender(_commandProcessor);
        }
Beispiel #5
0
        private static INeedARequestContext AddExternalBusMaybe(
            IBrighterOptions options,
            IAmAProducerRegistry producerRegistry,
            INeedMessaging messagingBuilder,
            MessageMapperRegistry messageMapperRegistry,
            InboxConfiguration inboxConfiguration,
            IAmAnOutboxSync <Message> outbox,
            IAmABoxTransactionConnectionProvider overridingConnectionProvider,
            IUseRpc useRequestResponse)
        {
            ExternalBusType externalBusType = GetExternalBusType(producerRegistry, useRequestResponse);

            if (externalBusType == ExternalBusType.None)
            {
                return(messagingBuilder.NoExternalBus());
            }
            else if (externalBusType == ExternalBusType.FireAndForget)
            {
                return(messagingBuilder.ExternalBus(
                           new ExternalBusConfiguration(producerRegistry, messageMapperRegistry, useInbox: inboxConfiguration),
                           outbox,
                           overridingConnectionProvider));
            }
            else if (externalBusType == ExternalBusType.RPC)
            {
                return(messagingBuilder.ExternalRPC(
                           new ExternalBusConfiguration(
                               producerRegistry,
                               messageMapperRegistry,
                               responseChannelFactory: options.ChannelFactory,
                               useInbox: inboxConfiguration),
                           outbox,
                           useRequestResponse.ReplyQueueSubscriptions));
            }

            throw new ArgumentOutOfRangeException("The external bus type requested was not understood");
        }