Example #1
0
 public void Repost(List<string> messageIds, IAmAMessageStore<Message> messageStore, IAmAMessageProducer messageProducer)
 {
     var foundMessages = GetMessagesFromStore(messageStore, messageIds);
     foreach (var foundMessage in foundMessages)
     {
         messageProducer.Send(foundMessage);
     }
 }
        /// <summary>
        /// Creates the specified configuration.
        /// </summary>
        /// <param name="gateway">The gateway to the control bus to send messages</param>
        /// <param name="logger">The logger to use</param>
        /// <param name="messageStore">The message store for outgoing messages to the control bus</param>
        /// <returns>IAmAControlBusSender.</returns>
        public IAmAControlBusSender Create(IAmAMessageStore<Message> messageStore, IAmAMessageProducer gateway)
        {
            var mapper = new MessageMapperRegistry(new SimpleMessageMapperFactory(() => new MonitorEventMessageMapper()));
            mapper.Register<MonitorEvent, MonitorEventMessageMapper>();

            return new ControlBusSender(CommandProcessorBuilder.With()
                    .Handlers(new HandlerConfiguration())
                    .DefaultPolicy()
                    .TaskQueues(new MessagingConfiguration(messageStore, gateway, mapper))
                    .RequestContextFactory(new InMemoryRequestContextFactory())
                    .Build()
                );
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MessagingConfiguration"/> class.
 /// </summary>
 /// <param name="messageStore">The message store.</param>
 /// <param name="messageProducer">The messaging gateway.</param>
 /// <param name="messageMapperRegistry">The message mapper registry.</param>
 /// <param name="messageStoreWriteTimeout">How long to wait when writing to the message store</param>
 /// <param name="messagingGatewaySendTimeout">How long to wait when sending via the gateway</param>
 public MessagingConfiguration(
     IAmAMessageStore<Message> messageStore,
     IAmAMessageProducer messageProducer,
     IAmAMessageMapperRegistry messageMapperRegistry,
     int messageStoreWriteTimeout = 300,
     int messagingGatewaySendTimeout = 300
     )
 {
     MessageStore = messageStore;
     MessageProducer = messageProducer;
     MessageMapperRegistry = messageMapperRegistry;
     MessageStoreWriteTimeout = messageStoreWriteTimeout;
     MessagingGatewaySendTimeout = messagingGatewaySendTimeout;
 }
Example #4
0
        public KafkaConfluentConsumerDeclareTests(ITestOutputHelper output)
        {
            string SupplyCertificateLocation()
            {
                //For different platforms, we have to figure out how to get the connection right
                //see: https://docs.confluent.io/platform/current/tutorials/examples/clients/docs/csharp.html

                return(RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "/usr/local/etc/[email protected]/cert.pem" : null);
            }

            // -- Confluent supply these values, see their .NET examples for your account
            // You need to set those values as environment variables, which we then read, in order
            // to run these tests

            const string groupId         = "Kafka Message Producer Send Test";
            string       bootStrapServer = Environment.GetEnvironmentVariable("CONFLUENT_BOOSTRAP_SERVER");
            string       userName        = Environment.GetEnvironmentVariable("CONFLUENT_SASL_USERNAME");
            string       password        = Environment.GetEnvironmentVariable("CONFLUENT_SASL_PASSWORD");

            _output   = output;
            _producer = new KafkaMessageProducerFactory(
                new KafkaMessagingGatewayConfiguration
            {
                Name             = "Kafka Producer Send Test",
                BootStrapServers = new[] { bootStrapServer },
                SecurityProtocol = SecurityProtocol.SaslSsl,
                SaslMechanisms   = SaslMechanism.Plain,
                SaslUsername     = userName,
                SaslPassword     = password,
                SslCaLocation    = SupplyCertificateLocation()
            },
                new KafkaPublication
            {
                Topic             = new RoutingKey(_topic),
                NumPartitions     = 1,
                ReplicationFactor = 3,
                //These timeouts support running on a container using the same host as the tests,
                //your production values ought to be lower
                MessageTimeoutMs = 10000,
                RequestTimeoutMs = 10000,
                MakeChannels     = OnMissingChannel.Assume //This will not make the topic
            }).Create();

            //This should force creation of the topic - will fail if no topic creation code
            _consumer = new KafkaMessageConsumerFactory(
                new KafkaMessagingGatewayConfiguration
            {
                Name             = "Kafka Producer Send Test",
                BootStrapServers = new[] { bootStrapServer },
                SecurityProtocol = SecurityProtocol.SaslSsl,
                SaslMechanisms   = SaslMechanism.Plain,
                SaslUsername     = userName,
                SaslPassword     = password,
                SslCaLocation    = SupplyCertificateLocation()
            })
                        .Create(new KafkaSubscription <MyCommand>(
                                    channelName: new ChannelName(_queueName),
                                    routingKey: new RoutingKey(_topic),
                                    groupId: groupId,
                                    numOfPartitions: 1,
                                    replicationFactor: 3,
                                    makeChannels: OnMissingChannel.Create
                                    )
                                );
        }
Example #5
0
 /// <summary>
 /// Constructor for use with a Producer
 /// </summary>
 /// <param name="outBox">The outbox to store messages - use InMemoryInbox if you do not require a persistent outbox</param>
 /// <param name="asyncOutBox">The outbox to store messages - use InMemoryInbox if you do not require a persistent outbox</param>
 /// <param name="producer">The Message producer</param>
 /// <param name="asyncProducer">The Message producer's async interface</param>
 public BrighterMessaging(IAmAnOutbox <Message> outBox, IAmAnOutboxAsync <Message> asyncOutBox, IAmAMessageProducer producer, IAmAMessageProducerAsync asyncProducer)
 {
     OutBox        = outBox;
     AsyncOutBox   = asyncOutBox;
     Producer      = producer;
     AsyncProducer = asyncProducer;
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OutputChannel"/> class.
 /// </summary>
 /// <param name="messageConsumer">The messageConsumer.</param>
 public OutputChannel(IAmAMessageProducer messageProducer)
 {
     _messageProducer = messageProducer;
     _messageProducerSupportsDelay = _messageProducer is IAmAMessageProducerSupportingDelay && (_messageProducer as IAmAMessageGatewaySupportingDelay).DelaySupported;
 }
 public BrighterMessaging(IAmAMessageStore <Message> messageStore, IAmAMessageProducer producer)
 {
     MessageStore = messageStore;
     Producer     = producer;
 }
 /// <summary>
 /// The <see cref="CommandProcessor"/> wants to support <see cref="CommandProcessor.Post{T}(T)"/> or <see cref="CommandProcessor.Repost"/> using Task Queues.
 /// You need to provide a policy to specify how QoS issues, specifically <see cref="CommandProcessor.RETRYPOLICY "/> or <see cref="CommandProcessor.CIRCUITBREAKER "/> 
 /// are handled by adding appropriate <see cref="Policies"/> when choosing this option.
 /// 
 /// </summary>
 /// <param name="configuration">The Task Queues configuration.</param>
 /// <returns>INeedARequestContext.</returns>
 public INeedARequestContext TaskQueues(MessagingConfiguration configuration)
 {
     _useTaskQueues = true;
     _messageStore = configuration.MessageStore;
     _messagingGateway = configuration.MessagingGateway;
     _messageMapperRegistry = configuration.MessageMapperRegistry;
     _messageStoreWriteTimeout = configuration.MessageStoreWriteTimeout;
     _messagingGatewaySendTimeout = configuration.MessagingGatewaySendTimeout;
     return this;
 }
 public FakeMessageProducerFactory(IAmAMessageProducer producer)
 {
     _producer = producer;
 }
Example #10
0
 public FakeMessageProducerFactory(IAmAMessageProducer producer)
 {
     _producer = producer;
 }
Example #11
0
 /// <summary>
 /// Constructor for use with a Producer
 /// </summary>
 /// <param name="outBox">The outbox to store messages - use InMemoryInbox if you do not require a persistent outbox</param>
 /// <param name="asyncOutBox">The outbox to store messages - use InMemoryInbox if you do not require a persistent outbox</param>
 /// <param name="producer">The Message producer</param>
 /// <param name="asyncProducer">The Message producer's async interface</param>
 /// <param name="useRequestReplyQueues">Use Request Reply Queues - This will need to set a Channel Factory as well.</param>
 public BrighterMessaging(IAmAnOutbox <Message> outBox, IAmAnOutboxAsync <Message> asyncOutBox, IAmAMessageProducer producer, IAmAMessageProducerAsync asyncProducer, bool useRequestReplyQueues = true)
 {
     OutBox                = outBox;
     AsyncOutBox           = asyncOutBox;
     Producer              = producer;
     AsyncProducer         = asyncProducer;
     UseRequestReplyQueues = useRequestReplyQueues;
 }
Example #12
0
        public void Repost(List <string> messageIds, IAmAMessageStore <Message> messageStore, IAmAMessageProducer messageProducer)
        {
            var foundMessages = GetMessagesFromStore(messageStore, messageIds);

            foreach (var foundMessage in foundMessages)
            {
                messageProducer.Send(foundMessage);
            }
        }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OutputChannel"/> class.
 /// </summary>
 /// <param name="messageConsumer">The messageConsumer.</param>
 public OutputChannel(IAmAMessageProducer messageProducer)
 {
     _messageProducer = messageProducer;
     _messageProducerSupportsDelay = _messageProducer is IAmAMessageProducerSupportingDelay && (_messageProducer as IAmAMessageGatewaySupportingDelay).DelaySupported;
 }
Example #14
0
        public PipelineInvoker(string requestId, TraceWriter traceWriter, Assembly coreAssembly, IAmAMessageProducer producer = null)
        {
            // todo: logger is static, but traceWriter is not. probably bad.
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Sink(new TraceWriterSink(traceWriter))
                         .CreateLogger();

            // todo: again, logg provider is static, but traceWriter is not. probably bad.
            // yep, turns out this doesn't work at all
            //LogProvider.SetCurrentLogProvider(new TraceWriterLogProvider(log));

            TinyIoCContainer.Current.Register(Log.Logger);

            if (_handlerConfig == null)
            {
                lock (_initialisationLock)
                {
                    if (_handlerConfig == null)
                    {
                        Log.Logger.Information("Initialising ({requestId})...", requestId);
                        _initialisedByRequestId = requestId;

                        _handlerConfig = new HandlerConfig();
                        _handlerConfig.RegisterDefaultHandlers();
                        _handlerConfig.RegisterMappersFromAssembly(coreAssembly);
                        _handlerConfig.RegisterSubscribersFromAssembly(coreAssembly);

                        if (producer != null)
                        {
                            _commandProcessor = CommandProcessorBuilder.With()
                                                .Handlers(_handlerConfig.HandlerConfiguration)
                                                .DefaultPolicy()
                                                .TaskQueues(new MessagingConfiguration(new InMemoryMessageStore(), producer, _handlerConfig.MessageMapperRegistry))
                                                .RequestContextFactory(new InMemoryRequestContextFactory())
                                                .Build();
                        }
                        else
                        {
                            _commandProcessor = CommandProcessorBuilder.With()
                                                .Handlers(_handlerConfig.HandlerConfiguration)
                                                .DefaultPolicy()
                                                .NoTaskQueues()
                                                .RequestContextFactory(new InMemoryRequestContextFactory())
                                                .Build();
                        }

                        TinyIoCContainer.Current.Register <IAmACommandProcessor>(_commandProcessor);
                    }
                }
            }
            else
            {
                Log.Logger.Information("Already initialised by {requestId}", _initialisedByRequestId);
            }
        }