Exemple #1
0
 public void Initialize(ReceivedHandler receivedEventHandler, SendingHandler sendingEventHandler)
 {
     sendArgs.UserToken     = this;
     receiveArgs.UserToken  = this;
     sendArgs.Completed    += new EventHandler <SocketAsyncEventArgs>(SendCallback);
     receiveArgs.Completed += new EventHandler <SocketAsyncEventArgs>(ReceiveCallback);
     handleReceived         = receivedEventHandler;
     handleSending          = sendingEventHandler;
 }
        public async Task Shares_state_with_handler_context()
        {
            var handlerContext = new TestableMessageHandlerContext();
            var uniformSession = new TestableUniformSession(handlerContext);
            var handler        = new SendingHandler(uniformSession);

            await handler.Handle(new SomeCommand(), handlerContext);

            Assert.AreEqual(2, uniformSession.PublishedMessages.Length);
            Assert.AreEqual(2, uniformSession.SentMessages.Length);
            Assert.AreEqual(2, handlerContext.PublishedMessages.Length);
            Assert.AreEqual(2, handlerContext.SentMessages.Length);

            Assert.IsTrue(handlerContext.DoNotContinueDispatchingCurrentMessageToHandlersWasCalled);
        }
        protected override IBinding DoBindProducer(string name, IMessageChannel outboundTarget, IProducerOptions producerOptions)
        {
            if (!(outboundTarget is ISubscribableChannel))
            {
                throw new ArgumentException("Binding is supported only for ISubscribableChannel instances");
            }

            IMessageHandler      producerMessageHandler;
            IProducerDestination producerDestination;

            try
            {
                producerDestination = _provisioningProvider.ProvisionProducerDestination(name, producerOptions);
                var errorChannel = producerOptions.ErrorChannelEnabled ? RegisterErrorInfrastructure(producerDestination) : null;
                producerMessageHandler = CreateProducerMessageHandler(producerDestination, producerOptions, outboundTarget, errorChannel);
            }
            catch (Exception e) when(e is BinderException || e is ProvisioningException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new BinderException("Exception thrown while building outbound endpoint", e);
            }

            if (producerOptions.AutoStartup && producerMessageHandler is ILifecycle producerMsgHandlerLifecycle)
            {
                producerMsgHandlerLifecycle.Start();
            }

            PostProcessOutputChannel(outboundTarget, producerOptions);
            var sendingHandler = new SendingHandler(ApplicationContext, producerMessageHandler, HeaderMode.EmbeddedHeaders.Equals(producerOptions.HeaderMode), _headersToEmbed, UseNativeEncoding(producerOptions));

            sendingHandler.Initialize();
            ((ISubscribableChannel)outboundTarget).Subscribe(sendingHandler);

            IBinding binding = new DefaultProducingMessageChannelBinding(
                this,
                name,
                outboundTarget,
                producerMessageHandler is ILifecycle lifecycle ? lifecycle : null,
                producerOptions,
                producerDestination,
                _logger);

            _producerBindingExist = true;
            return(binding);
        }