Пример #1
0
 /// <summary>
 /// Create a new instance of <see cref="DefaultServicebus"/>.
 /// </summary>
 public DefaultServicebus(ILogger <DefaultServicebus> logger, IOptionsMonitor <ServicebusConfiguration> config, IDomainEventSerializer serializer, IMessageTransport transport)
 {
     _logger     = logger;
     _config     = config;
     _serializer = serializer;
     _transport  = transport;
 }
 public DefaultAsyncEventPublisher(ISubscriptionStore subscriptionStore, IMessageTransport messageTransport, IMessageSerializer messageSerializer, ILoggerFactory loggerFactory)
 {
     _subscriptionStore = subscriptionStore;
     _messageTransport = messageTransport;
     _messageSerializer = messageSerializer;
     _logger = loggerFactory.Create("EventSourcing.DefaultAsyncEventPublisher");
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AutoUnregisterEvent{TResponse}"/> class.
 /// </summary>
 /// <param name="transport"> The transport. </param>
 /// <param name="receiver"> The receiver. </param>
 public AutoUnregisterEvent(
     IMessageTransport <TResponse> transport,
     EventHandler <MessageReceivedEventArgs <TResponse> > receiver)
 {
     this.transport = transport;
     this.receiver  = receiver;
 }
Пример #4
0
 public DefaultAsyncEventPublisher(ISubscriptionStore subscriptionStore, IMessageTransport messageTransport, IMessageSerializer messageSerializer, ILoggerFactory loggerFactory)
 {
     _subscriptionStore = subscriptionStore;
     _messageTransport  = messageTransport;
     _messageSerializer = messageSerializer;
     _logger            = loggerFactory.Create("EventSourcing.DefaultAsyncEventPublisher");
 }
Пример #5
0
 public ProcessTracker(IMessageTransport transport, JobObject jobObject, IProcess hostProcess, ProcessHelper processHelper)
 {
     this.transport = transport;
     this.jobObject = jobObject;
     this.hostProcess = hostProcess;
     this.processHelper = processHelper;
 }
Пример #6
0
        public async Task Run(IMessageTransport transport, CancellationToken ct)
        {
            TaskUtilities.AssertIsOnBackgroundThread();

            if (_runTask != null)
            {
                throw new InvalidOperationException("This host is already running.");
            }

            if (transport != null)
            {
                lock (_transportLock) {
                    _transport = transport;
                }
            }
            else if (_transport == null)
            {
                throw new ArgumentNullException(nameof(transport));
            }

            try {
                await(_runTask = RunWorker(ct));
            } catch (OperationCanceledException) when(ct.IsCancellationRequested)
            {
                // Expected cancellation, do not propagate, just exit process
            } catch (MessageTransportException ex) when(ct.IsCancellationRequested)
            {
                // Network errors during cancellation are expected, but should not be exposed to clients.
                throw new OperationCanceledException(new OperationCanceledException().Message, ex);
            } catch (Exception ex) {
                Trace.Fail("Exception in RHost run loop:\n" + ex);
                throw;
            }
        }
        /// <summary>
        /// Reads messages of specific type in given timespan.
        /// For more-refined filtering, an additional filter function can be
        /// provided.
        /// </summary>
        /// <returns>The read messages.</returns>
        /// <param name="transport">Transport.</param>
        /// <param name="readDuration">Read duration.</param>
        /// <param name="startAction">(Optional) Action to trigger before awaiting message.</param>
        /// <param name="filter">(Optional) Filter.</param>
        /// <typeparam name="T">Expected message type.</typeparam>
        public static IEnumerable <T> ReadMessages <T>(
            this IMessageTransport <T> transport, TimeSpan readDuration, Func <Task> startAction = null)
        {
            var lockObject         = new object();
            var blockingCollection = new BlockingCollection <T>();

            EventHandler <MessageReceivedEventArgs <T> > handler = (s, e) =>
            {
                lock (lockObject)
                {
                    blockingCollection.Add(e.Message);
                }
            };

            lock (lockObject)
            {
                transport.MessageReceived += handler;
                if (startAction != null)
                {
                    startAction();
                }
            }

            // Wait the specified time, then close the buffer to
            // stop receiving any more messages
            Task.Delay(readDuration).ContinueWith(t =>
            {
                transport.MessageReceived -= handler;
                blockingCollection.CompleteAdding();
            });

            return(blockingCollection.GetConsumingEnumerable());
        }
Пример #8
0
        public static async Task <T> WaitForMessageAsync <T, TBase>(
            this IMessageTransport <TBase> transport, TimeSpan timeout, Action startAction = null, Func <T, bool> filter = null)
            where T : TBase
        {
            return((T)(await TaskExtensions.EventTask <IMessageTransport <TBase>, MessageReceivedEventArgs <TBase> >(
                           transport,
                           startAction,
                           (o, e) => o.MessageReceived += e,
                           (o, e) => o.MessageReceived -= e,
                           (e) =>
            {
                if (e.Message is T)
                {
                    if (filter != null)
                    {
                        return filter((T)e.Message);
                    }

                    return true;
                }

                return false;
            },
                           timeout)).Message);
        }
 public DefaultAsyncMessageBus(ISubscriptionStorage subscriptionStorage, IMessageTransport messageTransport, IMessageSerializer messageSerializer)
 {
     _messageTransport              = messageTransport;
     _subscriptionStorage           = subscriptionStorage;
     _messageSerializer             = messageSerializer;
     _messageHandlerMetaDataManager = new MessageHandlerMetaDataManager <HandlerMetaData, AsyncHandlerAttribute>();
 }
Пример #10
0
        public static IEnumerable <T> ReadMessages <T>(
            this IMessageTransport <T> transport, TimeSpan readDuration, Action startAction = null)
        {
            var lockObject         = new object();
            var blockingCollection = new BlockingCollection <T>();

            EventHandler <MessageReceivedEventArgs <T> > handler = (s, e) =>
            {
                lock (lockObject)
                {
                    blockingCollection.Add(e.Message);
                }
            };

            lock (lockObject)
            {
                transport.MessageReceived += handler;
                if (startAction != null)
                {
                    startAction();
                }
            }

            Task.Delay(readDuration).ContinueWith(t =>
            {
                transport.MessageReceived -= handler;
                blockingCollection.CompleteAdding();
            });

            return(blockingCollection.GetConsumingEnumerable());
        }
Пример #11
0
        public static async Task <T> WaitForMessageAsync <T, TError, TBase>(
            this IMessageTransport <TBase> transport, TimeSpan timeout, Action startAction = null, Func <T, bool> filter = null, Func <TError, bool> errorFilter = null)
            where T : TBase
            where TError : TBase, IConvertToException
        {
            return((T)(await TaskExtensions.EventTask <IMessageTransport <TBase>, MessageReceivedEventArgs <TBase> >(
                           transport,
                           startAction,
                           (o, e) => o.MessageReceived += e,
                           (o, e) => o.MessageReceived -= e,
                           (e) =>
            {
                if (e.Message is TError)
                {
                    var error = (TError)e.Message;
                    if (errorFilter == null || !errorFilter(error))
                    {
                        throw error.ToException();
                    }
                }

                if (e.Message is T)
                {
                    if (filter != null)
                    {
                        return filter((T)e.Message);
                    }

                    return true;
                }

                return false;
            },
                           timeout)).Message);
        }
Пример #12
0
 public ProcessTracker(IMessageTransport transport, JobObject jobObject, IProcess hostProcess, ProcessHelper processHelper)
 {
     this.transport     = transport;
     this.jobObject     = jobObject;
     this.hostProcess   = hostProcess;
     this.processHelper = processHelper;
 }
Пример #13
0
        public JsonMessageTransport(IMessageTransport <SessionMessageBase> baseTransport, JsonSerializerSettings settings)
        {
            _serializerSettings = settings;

            _baseTransport = baseTransport;
            _baseTransport.MessageReceived += TransportMessageReceived;
        }
Пример #14
0
        public Listener([NotNull] ListenerConfiguration configuration,
                        [NotNull] ProcessingConfiguration processingConfiguration,
                        [NotNull] BufferManagerFactory bufferManagerFactory,
                        [NotNull] MessageTransportFactory messageTransportFactory)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }
            if (processingConfiguration == null)
            {
                throw new ArgumentNullException("processingConfiguration");
            }
            if (bufferManagerFactory == null)
            {
                throw new ArgumentNullException("bufferManagerFactory");
            }
            if (messageTransportFactory == null)
            {
                throw new ArgumentNullException("messageTransportFactory");
            }

            this._configuration        = configuration;
            this._bufferManagerFactory = bufferManagerFactory;

            this._clientConnectionInfoPool = new ObjectPool <ClientConnectionInfo>();
            this._disconnectSocketArgsPool = new ObjectPool <SocketAsyncEventArgs>();
            this._socketPool = new ObjectPool <Socket>();

            _connectionHolder         = new ConnectionHolder(configuration.ConnectionCapacity);
            _stoppedWaitHandle        = new ManualResetEvent(false);
            _messageTransport         = messageTransportFactory.GetMessageTransport(this);
            _compressionBufferManager = bufferManagerFactory.GetBufferManager(1024, 1024 * 8);
        }
Пример #15
0
 public Bus(IMessageTransport busTransport, IDependencyResolver dependencyResolver, MessageScanRules rules,
            Func <MessageHandlingExceptionRaisedEventArgs, Task> messageHandlingExceptionHandler = null)
 {
     this.busTransport       = busTransport;
     this.dependencyResolver = dependencyResolver;
     this.busMessages        = new BusMessages(rules);
     this.messageHandlingExceptionHandler = messageHandlingExceptionHandler;
 }
Пример #16
0
 public void given_an_initialized_bus()
 {
     messageTransport = Substitute.For <IMessageTransport>();
     bus = new Bus(messageTransport,
                   Substitute.For <IDependencyResolver>(),
                   new MessageScanRules()
                   .DefineCommandScanRuleWith(t => t.Namespace == "RockyBus.DemoMessages" && t.Name.EndsWith("Command"))
                   .DefineEventScanRuleWith(t => t.Namespace == "RockyBus.DemoMessages" && t.Name.EndsWith("Event")));
 }
Пример #17
0
        /// <summary>
        /// Registers a handler to receive messages of a given type.
        /// </summary>
        /// <typeparam name="TResponse">The response type to handle</typeparam>
        /// <param name="receiver">The response handler</param>
        /// <returns>A token that when disposed will unregister the receiver</returns>
        public IDisposable Subscribe <TResponse>(
            EventHandler <MessageReceivedEventArgs <TResponse> > receiver) where TResponse : class
        {
            IMessageTransport <TResponse> transport = this.transportFactory.CreateServerTransport <TResponse>(this.ClientId);

            transport.MessageReceived += receiver;

            return(new AutoUnregisterEvent <TResponse>(transport, receiver));
        }
Пример #18
0
        public RHost(string name, IRCallbacks callbacks, IMessageTransport transport, IActionLog log, CancellationTokenSource cts)
        {
            Check.ArgumentStringNullOrEmpty(nameof(name), name);

            _callbacks = callbacks;
            _transport = transport;
            _log       = log;
            _cts       = cts;
        }
Пример #19
0
        public RHost(string name, IRCallbacks callbacks, IMessageTransport transport, IActionLog log) {
            Check.ArgumentStringNullOrEmpty(nameof(name), name);

            _name = name;
            _callbacks = callbacks;
            _transport = transport;
            _log = log;
            _cts = new CancellationTokenSource();
            _cts.Token.Register(() => { _log.RHostProcessExited(); });
        }
Пример #20
0
 public DefaultAsyncEventSubscriberEndpoint(IAsyncEventHandlerProvider asyncEventHandlerProvider, ISubscriptionStore subscriptionStore, IMessageTransport messageTransport, IMessageSerializer messageSerializer, ILoggerFactory loggerFactory)
 {
     _asyncEventHandlerProvider = asyncEventHandlerProvider;
     _subscriptionStore         = subscriptionStore;
     _messageTransport          = messageTransport;
     _messageSerializer         = messageSerializer;
     _logger = loggerFactory.Create("EventSourcing.DefaultAsyncEventSubscriberEndpoint");
     _messageReceiveWorker = new WorkerThread(ReceiveMessage);
     _started = false;
 }
 public DefaultAsyncEventSubscriberEndpoint(IAsyncEventHandlerProvider asyncEventHandlerProvider, ISubscriptionStore subscriptionStore, IMessageTransport messageTransport, IMessageSerializer messageSerializer, ILoggerFactory loggerFactory)
 {
     _asyncEventHandlerProvider = asyncEventHandlerProvider;
     _subscriptionStore = subscriptionStore;
     _messageTransport = messageTransport;
     _messageSerializer = messageSerializer;
     _logger = loggerFactory.Create("EventSourcing.DefaultAsyncEventSubscriberEndpoint");
     _messageReceiveWorker = new WorkerThread(ReceiveMessage);
     _started = false;
 }
Пример #22
0
        public MessageChannel(IMessageTransport xport, IMessageFormat format)
        {
            _xport = xport;
            _format = format;
            _buffer = new List<byte>();
            _nextSeq = 1;

            _xport.DataReady += OnDataReady;
            _xport.ConnectionClosed += OnConnectionClosed;
        }
Пример #23
0
        public RHost(string name, IRCallbacks callbacks, IMessageTransport transport, CancellationTokenSource cts)
        {
            Check.ArgumentStringNullOrEmpty(nameof(name), name);

            _callbacks = callbacks;
            _transport = transport;
            _cts       = cts;

            _fileLogWriter = FileLogWriter.InTempFolder("Microsoft.R.Host.Client" + "_" + name);
            _log           = new LinesLog(_fileLogWriter);
        }
Пример #24
0
        public Publisher(IMessageTransport transport)
        {
            if (transport == null)
            {
                throw new ArgumentNullException(nameof(transport));
            }
            _transport = transport;

            _started = new TaskCompletionSource <object>();
            _stopped = false;
        }
Пример #25
0
        public RHost(string name, IRCallbacks callbacks, IMessageTransport transport, IActionLog log)
        {
            Check.ArgumentStringNullOrEmpty(nameof(name), name);

            Name       = name;
            _callbacks = callbacks;
            _transport = transport;
            Log        = log;
            _cts       = new CancellationTokenSource();
            _cts.Token.Register(() => { Log.RHostProcessExited(); });
        }
Пример #26
0
 public SubscriptionServer(
     IMessageTransport transport,
     ISubscriptionManager subscriptions,
     IEnumerable <IOperationMessageListener> messageListeners,
     ILogger <SubscriptionServer> logger)
 {
     _messageListeners = messageListeners;
     _logger           = logger;
     Subscriptions     = subscriptions;
     Transport         = transport;
 }
Пример #27
0
 public MessagePipeline(
     IEnumerable <IMessageFilter> filters,
     IMessageTransport transport,
     IEnumerable <IMessageHandler> handlers,
     IEnumerable <IMessageResponder> responders)
 {
     Filters    = filters;
     Transport  = transport;
     Handlers   = handlers;
     Responders = responders;
 }
        public JsonMessageTransport(IMessageTransport <SessionMessageBase> baseTransport, JsonConverter converter)
        {
            _serializerSettings = new JsonSerializerSettings()
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            _serializerSettings.Converters.Add(converter);

            _baseTransport = baseTransport;
            _baseTransport.MessageReceived += TransportMessageReceived;
        }
Пример #29
0
 public MessageNotificationHandler(
     IMessageTransport messageTransport,
     IMessageSerializer messageSerializer,
     IMessageMetadata messageMetadata,
     Uri uri
     )
 {
     _messageTransport  = messageTransport ?? throw new ArgumentNullException(nameof(messageTransport));
     _messageSerializer = messageSerializer ?? throw new ArgumentNullException(nameof(messageSerializer));
     _messageMetadata   = messageMetadata ?? throw new ArgumentNullException(nameof(messageMetadata));
     _uri = uri ?? throw new ArgumentNullException(nameof(uri));
 }
Пример #30
0
        private WebSocketMessageTransport CreateWebSocketMessageTransport()
        {
            lock (_transportLock) {
                if (_transport != null)
                {
                    throw new MessageTransportException("More than one incoming connection.");
                }

                var transport = new WebSocketMessageTransport();
                _transportTcs.SetResult(_transport = transport);
                return(transport);
            }
        }
Пример #31
0
        void DisposeMessageHandling()
        {
            if (messagingClient != null)
            {
                messagingClient.Dispose();
                messagingClient = null;
            }

            if (messageTransport != null)
            {
                messageTransport.Dispose();
                messageTransport = null;
            }
        }
Пример #32
0
        private MessagePipelineDelegate BuildHandler(
            IMessageTransport messageTransport,
            IEnumerable <IMessagePipelineHandler> messageHandlers,
            CancellationToken cancellationToken
            )
        {
            var terminalHandler = (MessagePipelineDelegate)(async message => await messageTransport.SendRequest(_uri, message, cancellationToken));

            var handle = messageHandlers
                         .Reverse()
                         .Aggregate(terminalHandler, (next, outerHandle) => async message => await outerHandle.Handle(message, next, cancellationToken));

            return(handle);
        }
Пример #33
0
        void _transport_OnMessageToUnknownDestination(MessageContainer message, IMessageTransport transport)
        {
            string dest = message.To;

            log.Debug("Message to remote destination {0}", dest);
            Uri               uri = new Uri(dest);
            string            sn  = string.Format("MessageTransport_{0}", uri.Scheme);
            IMessageTransport mt  = ServiceLocator.GetInstance <IMessageTransport>(sn);

            if (mt == null)
            {
                throw new Exception("No message transport configured for destination " + dest);
            }
            mt.Send(message);
        }
 void httpTransport_OnMessageArrived(MessageContainer message, IMessageTransport transport)
 {
     if (message.RetryCount > 0)
     { //we don't check if already received if message is sent for the first time
         if (ReceivedMessageRegistry.HasBeenReceived(message.UniqueId))
         {
             log.Warn("Message {0} has already been received. Ignoring", message.UniqueId);
             return;
         }
     }
     log.Info("Forwarding incoming http message {0} (from {1}) to {2}", message, message.From, _bus.Endpoint);
     message.To = _bus.Endpoint;
     _bus.Send(message);
     ReceivedMessageRegistry.RegisterReceived(message.UniqueId);
 }
 void httpTransport_OnMessageArrived(MessageContainer message, IMessageTransport transport)
 {
     if (message.RetryCount > 0)
     { //we don't check if already received if message is sent for the first time
         if (ReceivedMessageRegistry.HasBeenReceived(message.UniqueId))
         {
             log.Warn("Message {0} has already been received. Ignoring", message.UniqueId);
             return;
         }
     }
     log.Info("Forwarding incoming http message {0} (from {1}) to {2}", message, message.From, _bus.Endpoint);
     message.To = _bus.Endpoint;
     _bus.Send(message);
     ReceivedMessageRegistry.RegisterReceived(message.UniqueId);
 }
Пример #36
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="transport">Message transport used as a backend for this message bus</param>
 public MessageBus(IMessageTransport transport, IMessageDispatcher dispatcher, ISerializeMessages serializer, IServiceResolver serviceResolver)
 {
     log = LogManager.GetLogger("BUS_" + transport.Endpoint);
     log.Info("Message Bus {0} created", transport.Endpoint);
     MessageSerializer            = serializer;
     Dispatcher                   = dispatcher;
     ServiceLocator               = serviceResolver;
     _transport                   = transport;
     _transport.OnMessageArrived += new MessageArrived(_transport_OnMessageArrived);
     _transport.OnMessageToUnknownDestination += new MessageArrived(_transport_OnMessageToUnknownDestination);
     SubscriptionService = new DummySubscriptionService();
     BatchOutgoingMessagesInTransaction   = true;
     MessageHandlerTransactionScopeOption = TransactionScopeOption.Required;
     UseTransactionScope         = true;
     DefaultSubscriptionLifetime = TimeSpan.FromHours(48);
     PublishLocalByDefault       = true;
 }
Пример #37
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="transport">Message transport used as a backend for this message bus</param>
 public MessageBus(IMessageTransport transport, IMessageDispatcher dispatcher, ISerializeMessages serializer, IServiceResolver serviceResolver)
 {
     log = LogManager.GetLogger("BUS_" + transport.Endpoint);
     log.Info("Message Bus {0} created", transport.Endpoint);
     MessageSerializer = serializer;
     Dispatcher = dispatcher;
     ServiceLocator = serviceResolver;
     _transport = transport;
     _transport.OnMessageArrived += new MessageArrived(_transport_OnMessageArrived);
     _transport.OnMessageToUnknownDestination += new MessageArrived(_transport_OnMessageToUnknownDestination);
     SubscriptionService = new DummySubscriptionService();
     BatchOutgoingMessagesInTransaction = true;
     MessageHandlerTransactionScopeOption = TransactionScopeOption.Required;
     UseTransactionScope = true;
     DefaultSubscriptionLifetime = TimeSpan.FromHours(48);
     PublishLocalByDefault = true;
 }
        public MessagePreprocessResult HandleIncomingMessage(MessageContainer message, IMessageTransport transport)
        {
            log.Info("Preprocessing message: {0}", message.BodyStr);
            var m = typeRe.Match(message.BodyStr);
            if (!m.Success)
            {
                log.Warn("Did not match message type. Ignoring the message!");
                return MessagePreprocessResult.CancelFurtherProcessing;
            }
            string mtype = m.Groups[1].Captures[0].Value;
            int idx = mtype.IndexOf(',');
            if (idx > 0) mtype = mtype.Substring(0, idx);
            log.Info("Message type is {0}", mtype);
            if (mtype.StartsWith("NGinnBPM.MessageBus.Messages"))
            {
                log.Info("It's a control message so we process it as usual");
                return MessagePreprocessResult.ContinueProcessing;
            }
            List<MessageContainer> messages = new List<MessageContainer>();
            //now get destination endpoints from the subscribers database
            //and prepare a message clone for each destination
            List<string> destinations = new List<string>();
            foreach (string typeName in new string[] { mtype, "System.Object" })
            {
                foreach (string destination in SubscriptionManager.GetTargetEndpoints(typeName))
                {
                    if (!destinations.Contains(destination)) destinations.Add(destination);
                }
            }
            foreach (string destination in destinations)
            {
                var msg = message.Clone() as MessageContainer;
                msg.To = destination; //set destination. We don't update msg.From so the original endpoint is unchanged
                messages.Add(msg);
            }

            if (messages.Count > 0)
            {
                //send messages to their destinations
                transport.SendBatch(messages, MessageBusContext.ReceivingConnection);
                log.Info("Sent message to {0} destinations", messages.Count);
            }
            return MessagePreprocessResult.CancelFurtherProcessing;
        }
Пример #39
0
 void _transport_OnMessageToUnknownDestination(MessageContainer message, IMessageTransport transport)
 {
     string dest = message.To;
     log.Debug("Message to remote destination {0}", dest);
     Uri uri = new Uri(dest);
     string sn = string.Format("MessageTransport_{0}", uri.Scheme);
     IMessageTransport mt = ServiceLocator.GetInstance<IMessageTransport>(sn);
     if (mt == null) throw new Exception("No message transport configured for destination " + dest);
     mt.Send(message);
 }
 public HttpMessageGateway(IMessageTransport busTransport, IMessageTransport httpTransport)
 {
     _bus = busTransport;
     _http = httpTransport;
     httpTransport.OnMessageArrived += new MessageArrived(httpTransport_OnMessageArrived);
 }
Пример #41
0
 protected virtual MessagePreprocessResult PreprocessIncomingMessage(MessageContainer mc, IMessageTransport t, out List<IPreprocessMessages> callbacks)
 {
     List<IPreprocessMessages> callb = null;
     callbacks = callb;
     //todo: allow for ordering of message preprocessors
     foreach (IPreprocessMessages pm in this.ServiceLocator.GetAllInstances<IPreprocessMessages>())
     {
         ServiceLocator.ReleaseInstance(pm);
         var res = pm.HandleIncomingMessage(mc, this, t);
         if (callb == null) callb = new List<IPreprocessMessages>();
         callb.Add(pm);
         if (res != MessagePreprocessResult.ContinueProcessing) return res;
     }
     callbacks = callb;
     return MessagePreprocessResult.ContinueProcessing;
 }
 public void Add(IMessageTransport transport)
 {
     transports.Add(transport);
 }
Пример #43
0
 public Mailer(IMessageEnvelopeFactory messageEnvelopeFactory, IMessageTransport messageTransport, IRepository<Email> emailRepository)
 {
     _messageEnvelopeFactory = messageEnvelopeFactory;
     _messageTransport = messageTransport;
     _emailRepository = emailRepository;
 }
Пример #44
0
 public LogglyClient()
 {
     _transport = TransportFactory();
 }
Пример #45
0
 void _transport_OnMessageArrived(MessageContainer message, IMessageTransport transport)
 {
     Debug.Assert(message.BodyStr != null && message.Body == null);
     List<IPreprocessMessages> callbacks = null;
     MessagePreprocessResult disp = PreprocessIncomingMessage(message, transport, out callbacks);
     if (disp == MessagePreprocessResult.CancelFurtherProcessing)
     {
         return;
     }
     Exception e2 = null;
     try
     {
         DeserializeMessage(message);
         Debug.Assert(message.Body != null);
         DispatchIncomingMessage(message);
     }
     catch (Exception ex)
     {
         e2 = ex;
         throw;
     }
     finally
     {
         if (callbacks != null)
         {
             callbacks.Reverse();
             callbacks.ForEach(x => {
                 try
                 {
                     x.AfterMessageProcessed(message, this, this._transport, e2);
                 }
                 catch (Exception e3)
                 {
                     log.Warn("Callback error: {0}", e3);
                 }
             });
         }
     }
 }
Пример #46
0
        public async Task Run(IMessageTransport transport, CancellationToken ct) {
            TaskUtilities.AssertIsOnBackgroundThread();

            if (_runTask != null) {
                throw new InvalidOperationException("This host is already running.");
            }

            if (transport != null) {
                lock (_transportLock) {
                    _transport = transport;
                }
            } else if (_transport == null) {
                throw new ArgumentNullException(nameof(transport));
            }

            try {
                await (_runTask = RunWorker(ct));
            } catch (OperationCanceledException) when (ct.IsCancellationRequested) {
                // Expected cancellation, do not propagate, just exit process
            } catch (MessageTransportException ex) when (ct.IsCancellationRequested) {
                // Network errors during cancellation are expected, but should not be exposed to clients.
                throw new OperationCanceledException(new OperationCanceledException().Message, ex);
            } catch (Exception ex) {
                Trace.Fail("Exception in RHost run loop:\n" + ex);
                throw;
            }
        }
Пример #47
0
        private WebSocketMessageTransport CreateWebSocketMessageTransport() {
            lock (_transportLock) {
                if (_transport != null) {
                    throw new MessageTransportException("More than one incoming connection.");
                }

                var transport = new WebSocketMessageTransport();
                _transportTcs.SetResult(_transport = transport);
                return transport;
            }
        }