public MessageHandlingListener(Bus bus, IMessageNamingService namingService,
            ISerializationService serializationService, IEnumerable<IMessageHandler> messageHandlers)
        {
            if (bus == null) throw new ArgumentNullException("bus");
            if (namingService == null) throw new ArgumentNullException("namingService");
            if (serializationService == null) throw new ArgumentNullException("serializationService");
            if (messageHandlers == null) throw new ArgumentNullException("messageHandlers");

            var handlerList = messageHandlers.Where(h => h != null).ToList();
            if (!handlerList.Any()) throw new ArgumentNullException("messageHandlers");

            _bus = bus;
            _messageNamingService = namingService;
            _serializationService = serializationService;
            _messageHandlers = handlerList;
        }
示例#2
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;
            }
        }
示例#3
0
        public static async Task HandleMessage(IMessageNamingService messageNamingService,
            ISerializationService serializationService, IEnumerable<IMessageHandler> messageHandlers, Message message,
            IMessageContext messageContext, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (message.Headers.Expires < DateTime.UtcNow)
            {
                Log.WarnFormat("Discarding expired \"{0}\" message (ID {1}, expired {2})", message.Headers.MessageName,
                    message.Headers.MessageId, message.Headers.Expires);

                messageContext.Acknowledge();
                return;
            }

            var messageType = messageNamingService.GetTypeForName(message.Headers.MessageName);
            var serializer = serializationService.GetSerializer(message.Headers.ContentType);
            var messageContent = serializer.Deserialize(message.Content, messageType);
            var handlingTasks =
                messageHandlers.Select(
                    handler => handler.HandleMessage(messageContent, messageContext, cancellationToken));

            await Task.WhenAll(handlingTasks);
        }
示例#4
0
文件: Bus.cs 项目: tdbrian/Platibus
        /// <summary>
        /// Initializes a new <see cref="Bus"/> with the specified configuration and services
        /// provided by the host
        /// </summary>
        /// <param name="configuration">The core bus configuration</param>
        /// <param name="baseUri">The base URI provided by the host</param>
        /// <param name="transportService">The transport service provided by the host</param>
        /// <param name="messageQueueingService">The message queueing service provided by the host</param>
        /// <exception cref="ArgumentNullException">Thrown if any of the parameters are <c>null</c></exception>
        public Bus(IPlatibusConfiguration configuration, Uri baseUri, ITransportService transportService, IMessageQueueingService messageQueueingService)
        {
            if (configuration == null) throw new ArgumentNullException("configuration");
            if (baseUri == null) throw new ArgumentNullException("baseUri");
            if (transportService == null) throw new ArgumentNullException("transportService");
            if (messageQueueingService == null) throw new ArgumentNullException("messageQueueingService");

            _baseUri = baseUri;
            _transportService = transportService;
            _messageQueueingService = messageQueueingService;

            // TODO: Throw configuration exception if message queueing service, message naming
            // service, or serialization service are null

            _messageJournalingService = configuration.MessageJournalingService;
            _messageNamingService = configuration.MessageNamingService;
            _serializationService = configuration.SerializationService;

            _endpoints = new ReadOnlyEndpointCollection(configuration.Endpoints);
            _topics = configuration.Topics.ToList();
            _sendRules = configuration.SendRules.ToList();
            _handlingRules = configuration.HandlingRules.ToList();
            _subscriptions = configuration.Subscriptions.ToList();
        }
示例#5
0
 /// <summary>
 /// Initializes a new <see cref="MessageMarshaller"/>
 /// </summary>
 /// <param name="messageNamingService">A service used to map <see cref="MessageName"/>s
 /// onto runtime <see cref="System.Type"/>s when deserializing content</param>
 /// <param name="serializationService">A service used to parse string content onto the
 /// <see cref="System.Type"/>s identified by the <paramref name="messageNamingService"/></param>
 /// <param name="defaultContentType">The default content type to assume if the
 /// <see cref="IMessageHeaders.ContentType"/> header is not specified</param>
 public MessageMarshaller(IMessageNamingService messageNamingService, ISerializationService serializationService, string defaultContentType)
 {
     _messageNamingService = messageNamingService ?? new DefaultMessageNamingService();
     _serializationService = serializationService ?? new DefaultSerializationService();
     _defaultContentType   = string.IsNullOrWhiteSpace(defaultContentType) ? "text/plain" : defaultContentType;
 }
示例#6
0
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new <see cref="T:Platibus.Serialization.MessageMarshaller" />
 /// </summary>
 /// <param name="messageNamingService">A service used to map <see cref="T:Platibus.MessageName" />s
 /// onto runtime <see cref="T:System.Type" />s when deserializing content</param>
 /// <param name="serializationService">A service used to parse string content onto the
 /// <see cref="T:System.Type" />s identified by the <paramref name="messageNamingService" /></param>
 public MessageMarshaller(IMessageNamingService messageNamingService, ISerializationService serializationService)
     : this(messageNamingService, serializationService, null)
 {
 }