/// <summary>
        /// Initializes a new <see cref="MessageJournalConsumer"/> with the specified configuration
        /// and services
        /// </summary>
        /// <param name="bus">A configured and initialized bus instance that will be used to handle
        /// incoming messages</param>
        /// <param name="messageJournal">The message journal from which entries will be consumed</param>
        /// <param name="options">(Optional) Options to customize the behavior of the message journal consumer</param>
        /// <exception cref="ArgumentNullException">Thrown if any of the parameters are <c>null</c></exception>
        public MessageJournalConsumer(IBus bus, IMessageJournal messageJournal, MessageJournalConsumerOptions options)
        {
            if (bus == null)
            {
                throw new ArgumentNullException(nameof(bus));
            }

            _diagnosticService = DiagnosticService.DefaultInstance;
            _messageJournal    = messageJournal ?? throw new ConfigurationErrorsException("Message journal is required");
            _bus = Task.FromResult(bus);

            var myOptions = options ?? new MessageJournalConsumerOptions();

            _filter    = myOptions.Filter;
            _batchSize = myOptions.BatchSize > 0
                ? myOptions.BatchSize
                : MessageJournalConsumerOptions.DefaultBatchSize;

            _rethrowExceptions  = myOptions.RethrowExceptions;
            _haltAtEndOfJournal = myOptions.HaltAtEndOfJournal;
            _pollingInterval    = myOptions.PollingInterval > TimeSpan.Zero
                ? myOptions.PollingInterval
                : MessageJournalConsumerOptions.DefaultPollingInterval;

            _progress = myOptions.Progress;
        }
        /// <summary>
        /// Initializes a new <see cref="MessageJournalConsumer"/> with the specified configuration
        /// and services
        /// </summary>
        /// <remarks>
        /// Message journal consumers created with this constructor use an internal <see cref="Bus"/>
        /// instance based on the <see cref="LoopbackTransportService"/> and <see cref="VirtualMessageQueueingService"/>
        /// to minimize overhead of message processing.
        /// </remarks>
        /// <param name="configuration">The bus configuration</param>
        /// <param name="options">(Optional) Options to customize the behavior of the message journal consumer</param>
        /// <exception cref="ArgumentNullException">Thrown if any of the parameters are <c>null</c></exception>
        public MessageJournalConsumer(IPlatibusConfiguration configuration, MessageJournalConsumerOptions options)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            _diagnosticService = configuration.DiagnosticService;
            _messageJournal    = configuration.MessageJournal ?? throw new ConfigurationErrorsException("Message journal is required");
            _bus = InitBus(configuration);

            var myOptions = options ?? new MessageJournalConsumerOptions();

            _filter    = myOptions.Filter;
            _batchSize = myOptions.BatchSize > 0
                ? myOptions.BatchSize
                : MessageJournalConsumerOptions.DefaultBatchSize;

            _rethrowExceptions  = myOptions.RethrowExceptions;
            _haltAtEndOfJournal = myOptions.HaltAtEndOfJournal;
            _pollingInterval    = myOptions.PollingInterval > TimeSpan.Zero
                ? myOptions.PollingInterval
                : MessageJournalConsumerOptions.DefaultPollingInterval;

            _progress = myOptions.Progress;
        }
Beispiel #3
0
        protected Mock <MessageJournalStub> GiveMockMessageJournal()
        {
            var mockMessageJournal = new Mock <MessageJournalStub>
            {
                CallBase = true
            };

            MessageJournal = mockMessageJournal.Object;
            return(mockMessageJournal);
        }
Beispiel #4
0
        private RabbitMQHost(IRabbitMQHostConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var diagnosticService = configuration.DiagnosticService;
            var baseUri           = configuration.BaseUri.WithoutTrailingSlash();

            _connectionManager = new ConnectionManager();
            var encoding = configuration.Encoding ?? Encoding.UTF8;

            var defaultQueueOptions = new QueueOptions
            {
                AutoAcknowledge  = configuration.AutoAcknowledge,
                MaxAttempts      = configuration.MaxAttempts,
                ConcurrencyLimit = configuration.ConcurrencyLimit,
                RetryDelay       = configuration.RetryDelay,
                IsDurable        = configuration.IsDurable
            };

            var securityTokenService = configuration.SecurityTokenService ?? new JwtSecurityTokenService();

            _messageJournal = configuration.MessageJournal;

            var queueingOptions = new RabbitMQMessageQueueingOptions(baseUri)
            {
                ConnectionManager    = _connectionManager,
                DefaultQueueOptions  = defaultQueueOptions,
                DiagnosticService    = diagnosticService,
                Encoding             = encoding,
                SecurityTokenService = securityTokenService
            };

            _messageQueueingService = new RabbitMQMessageQueueingService(queueingOptions);

            var transportServiceOptions = new RabbitMQTransportServiceOptions(baseUri, _connectionManager)
            {
                DiagnosticService    = configuration.DiagnosticService,
                MessageJournal       = configuration.MessageJournal,
                SecurityTokenService = configuration.SecurityTokenService,
                Encoding             = configuration.Encoding,
                DefaultQueueOptions  = defaultQueueOptions,
                Topics = configuration.Topics
            };

            _transportService = new RabbitMQTransportService(transportServiceOptions);

            Bus = new Bus(configuration, configuration.BaseUri, _transportService, _messageQueueingService);
        }
Beispiel #5
0
 public HttpTransportService(Uri baseUri, IEndpointCollection endpoints,
                             IMessageQueueingService messageQueueingService, IMessageJournal messageJournal,
                             ISubscriptionTrackingService subscriptionTrackingService,
                             bool bypassTransportLocalDestination = false,
                             IDiagnosticService diagnosticService = null)
     : this(new HttpTransportServiceOptions(baseUri, messageQueueingService, subscriptionTrackingService)
 {
     DiagnosticService = diagnosticService,
     Endpoints = endpoints,
     MessageJournal = messageJournal,
     BypassTransportLocalDestination = bypassTransportLocalDestination,
     HttpClientFactory = new BasicHttpClientFactory()
 })
 {
 }
        private HttpServer(IHttpServerConfiguration configuration)
        {
            _baseUri = configuration.BaseUri;

            _metricsCollector  = new HttpMetricsCollector();
            _diagnosticService = configuration.DiagnosticService;
            _diagnosticService.AddSink(_metricsCollector);

            _subscriptionTrackingService = configuration.SubscriptionTrackingService;
            _messageQueueingService      = configuration.MessageQueueingService;
            _messageJournal = configuration.MessageJournal;

            var transportServiceOptions = new HttpTransportServiceOptions(_baseUri, _messageQueueingService, _subscriptionTrackingService)
            {
                DiagnosticService = configuration.DiagnosticService,
                Endpoints         = configuration.Endpoints,
                MessageJournal    = configuration.MessageJournal,
                BypassTransportLocalDestination = configuration.BypassTransportLocalDestination
            };

            TransportService = new HttpTransportService(transportServiceOptions);

            _bus = new Bus(configuration, _baseUri, TransportService, _messageQueueingService);

            var authorizationService = configuration.AuthorizationService;

            _resourceRouter = new ResourceTypeDictionaryRouter(configuration.BaseUri)
            {
                { "message", new MessageController(TransportService.ReceiveMessage, authorizationService) },
                { "topic", new TopicController(_subscriptionTrackingService, configuration.Topics, authorizationService) },
                { "journal", new JournalController(configuration.MessageJournal, configuration.AuthorizationService) },
                { "metrics", new MetricsController(_metricsCollector) }
            };
            _httpListener = InitHttpListener(_baseUri, configuration.AuthenticationSchemes);

            var acceptBlockOptions = new ExecutionDataflowBlockOptions
            {
                CancellationToken = _cancellationTokenSource.Token
            };

            if (configuration.ConcurrencyLimit > 0)
            {
                acceptBlockOptions.MaxDegreeOfParallelism = configuration.ConcurrencyLimit;
            }

            _acceptBlock = new ActionBlock <HttpListenerContext>(async ctx => await Accept(ctx), acceptBlockOptions);
        }
Beispiel #7
0
        /// <summary>
        /// Initializes a new <see cref="HttpTransportService"/>
        /// </summary>
        /// <param name="options">The HTTP transport service configuration</param>
        public HttpTransportService(HttpTransportServiceOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _baseUri   = options.BaseUri.WithTrailingSlash();
            _endpoints = options.Endpoints = options.Endpoints ?? EndpointCollection.Empty;

            _messageQueueingService          = options.MessageQueueingService;
            _messageJournal                  = options.MessageJournal;
            _subscriptionTrackingService     = options.SubscriptionTrackingService;
            _bypassTransportLocalDestination = options.BypassTransportLocalDestination;
            _diagnosticService               = options.DiagnosticService ?? DiagnosticService.DefaultInstance;
            _httpClientFactory               = options.HttpClientFactory ?? new BasicHttpClientFactory();
            _outboundQueueName               = "Outbound";
        }
        public async Task <MessageJournalPosition> GetNext(IMessageJournal messageJournal, string consumer)
        {
            if (messageJournal == null)
            {
                throw new ArgumentNullException(nameof(messageJournal));
            }
            if (string.IsNullOrWhiteSpace(consumer))
            {
                throw new ArgumentNullException(nameof(consumer));
            }

            var filter = Builders <JournalConsumerProgress> .Filter.Eq(x => x.Consumer, consumer.Trim().ToLower());

            var progress = await _collection.Find(filter).Limit(1).FirstOrDefaultAsync();

            return(progress == null || string.IsNullOrWhiteSpace(progress.Next)
                ? await messageJournal.GetBeginningOfJournal()
                : messageJournal.ParsePosition(progress.Next));
        }
Beispiel #9
0
        public JournalingUpdateService(IMessageJournal messageJournal,
                                       ISerializationService serializationService,
                                       IJournalConsumerProgressTracker tracker,
                                       IMongoDatabase database,
                                       IMessageNamingService messageNamingService,
                                       IConfiguration configuration)
        {
            _messageJournal       = messageJournal;
            _serializationService = serializationService;
            _tracker = tracker;
            _messageNamingService = messageNamingService;

            _eventProcessor = new CustomerJournalEventProcessor(database);

            // MessageJournalFilter does not work with mongo2 go
            if (configuration.GetValue <bool>("UseMongo2Go"))
            {
                Filter = null;
            }
        }
        /// <summary>
        /// Initializes a new <see cref="RabbitMQTransportService"/>
        /// </summary>
        /// <param name="options">The options that govern the configuration and behavior of the
        /// RabbitMQ transport</param>
        public RabbitMQTransportService(RabbitMQTransportServiceOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            _baseUri              = options.BaseUri;
            _connectionManager    = options.ConnectionManager;
            _diagnosticService    = options.DiagnosticService ?? DiagnosticService.DefaultInstance;
            _messageJournal       = options.MessageJournal;
            _securityTokenService = options.SecurityTokenService ?? new JwtSecurityTokenService();
            _encoding             = options.Encoding ?? Encoding.GetEncoding(RabbitMQDefaults.Encoding);
            _defaultQueueOptions  = options.DefaultQueueOptions ?? new QueueOptions();

            var connection = _connectionManager.GetConnection(_baseUri);
            var topics     = (options.Topics ?? Enumerable.Empty <TopicName>()).Where(t => t != null);

            using (var channel = connection.CreateModel())
            {
                foreach (var topicName in topics)
                {
                    var exchangeName = topicName.GetTopicExchangeName();
                    channel.ExchangeDeclare(exchangeName, "fanout", _defaultQueueOptions.IsDurable, false, new Dictionary <string, object>());
                    _diagnosticService.Emit(
                        new RabbitMQEventBuilder(this, RabbitMQEventType.RabbitMQExchangeDeclared)
                    {
                        Detail        = "Fanout exchange declared for topic",
                        Exchange      = exchangeName,
                        Topic         = topicName,
                        ChannelNumber = channel.ChannelNumber
                    }.Build());
                }
            }

            _inboundQueue = new RabbitMQQueue(connection, InboxQueueName, this,
                                              _encoding, _defaultQueueOptions, _diagnosticService, _securityTokenService, null);

            _inboundQueue.Init();
        }
Beispiel #11
0
        /// <summary>
        /// Initializes a new <see cref="ManagedBus"/> with the specified <paramref name="configuration"/>
        /// </summary>
        /// <param name="configuration">The configuration used to initialize the bus instance
        /// and its related components</param>
        public ManagedBus(IIISConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }
            var baseUri = configuration.BaseUri;

            _subscriptionTrackingService = configuration.SubscriptionTrackingService;
            _messageQueueingService      = configuration.MessageQueueingService;
            _messageJournal = configuration.MessageJournal;

            var transportServiceOptions = new HttpTransportServiceOptions(baseUri, _messageQueueingService, _subscriptionTrackingService)
            {
                DiagnosticService = configuration.DiagnosticService,
                Endpoints         = configuration.Endpoints,
                MessageJournal    = configuration.MessageJournal,
                BypassTransportLocalDestination = configuration.BypassTransportLocalDestination
            };

            TransportService = new HttpTransportService(transportServiceOptions);

            Bus = InitBus(configuration, TransportService, _messageQueueingService).GetResultFromCompletionSource();
        }
Beispiel #12
0
 protected MessageJournalReadTests(IMessageJournal messageJournal)
 {
     MessageJournal = messageJournal;
 }
Beispiel #13
0
 protected void GivenMessageJournalingDisabled()
 {
     MessageJournal = null;
 }
Beispiel #14
0
 public JournalControllerTests()
 {
     MessageJournal  = new MessageJournalStub();
     ResponseContent = new MemoryStream();
 }
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new <see cref="T:Platibus.Journaling.MessageJournalConsumer" /> with the specified configuration
 /// and services
 /// </summary>
 /// <param name="bus">A configured and initialized bus instance</param>
 /// <param name="messageJournal">The message journal from which entries will be consumed</param>
 /// <exception cref="T:System.ArgumentNullException">Thrown if any of the parameters are <c>null</c></exception>
 public MessageJournalConsumer(IBus bus, IMessageJournal messageJournal) : this(bus, messageJournal, null)
 {
 }
 /// <summary>
 /// Initializes a new <see cref="SanitizedMessageJournal"/> wrapping the specified
 /// <paramref name="journal"/>
 /// </summary>
 /// <param name="journal">The message journal to wrap</param>
 public SanitizedMessageJournal(IMessageJournal journal)
 {
     _inner = journal ?? throw new ArgumentNullException(nameof(journal));
 }
Beispiel #17
0
 /// <summary>
 /// Initializes a <see cref="JournalController"/> with the specified
 /// <paramref name="messageJournal"/>
 /// </summary>
 /// <param name="messageJournal">The message journal</param>
 /// <param name="authorizationService">(Optional) Used to determine whether a requestor is
 /// authorized to query the message journal</param>
 public JournalController(IMessageJournal messageJournal, IAuthorizationService authorizationService = null)
 {
     _messageJournal       = messageJournal;
     _authorizationService = authorizationService;
 }
Beispiel #18
0
 public FilteredMessageJournal(IMessageJournal inner, IEnumerable <MessageJournalCategory> categories = null)
 {
     _inner      = inner ?? throw new ArgumentNullException(nameof(inner));
     _categories = (categories ?? Enumerable.Empty <MessageJournalCategory>()).ToList();
 }
Beispiel #19
0
 /// <summary>
 /// Initialies a new <see cref="LoopbackTransportService"/> with the specified
 /// <paramref name="messageJournal"/>
 /// </summary>
 /// <param name="messageJournal">(Optional) The journal to which copies of sent, received, and/or
 /// published messages will be recorded</param>
 public LoopbackTransportService(IMessageJournal messageJournal)
 {
     _messageJournal = messageJournal;
 }