protected virtual void AddHeadersTo(Message message)
 {
     if (!ManualAddressing && RemoteAddress != null)
     {
         RemoteAddress.ApplyTo(message);
     }
 }
示例#2
0
        public Message Request(Message message, TimeSpan timeout)
        {
            RemoteAddress.ApplyTo(message);

            //TODO: setup reply queue and wait for reply message.
            var rabbitMsg = message.AsRabbitMqMessage();

            var queueResult = Model.QueueDeclare();

            var specs = new Dictionary <string, object> {
                { "x-match", "all" }, { "correlation-id", rabbitMsg.CorrelationId }
            };

            Model.QueueBind(queueResult.QueueName, rabbitMsg.ReplyTopic, string.Empty, specs);

            var waitReplyDelegate = new WaitReplyDelegate(WaitReply);

            var asyncresult = waitReplyDelegate.BeginInvoke(rabbitMsg, queueResult.QueueName, timeout, null, null);

            Model.BasicPublish(rabbitMsg.Topic, rabbitMsg.RoutingKey, rabbitMsg.Properties, rabbitMsg.Body);

            asyncresult.AsyncWaitHandle.WaitOne();

            return(waitReplyDelegate.EndInvoke(asyncresult));
        }
        public async Task <Message> RequestAsync(Message message, TimeSpan timeout)
        {
            RemoteAddress?.ApplyTo(message);
            var requestContext = new DispatcherClientRequestContext(message);
            var cts            = new CancellationTokenSource(timeout);
            await _serviceChannelDispatch.DispatchAsync(requestContext, cts.Token);

            var replyMessage = Helpers.TestHelper.ConvertMessage(requestContext.ReplyMessage);

            cts.Dispose();
            return(replyMessage);
        }
        public async Task <Message> RequestAsync(Message message, TimeSpan timeout)
        {
            CancellationTokenSource cts = new CancellationTokenSource(timeout);

            RemoteAddress?.ApplyTo(message);
            var requestContext = new DispatcherClientRequestContext(message);
            await _serviceChannelDispatch.DispatchAsync(requestContext);

            CoreWCF.Channels.Message coreReplyMessage = await requestContext.ReplyMessageTask;
            Message replyMessage = Helpers.TestHelper.ConvertMessage(coreReplyMessage);

            return(replyMessage);
        }
示例#5
0
        /// <summary>
        /// Sends a message on the current output channel within a specified interval of time.
        /// </summary>
        /// <param name="message">The <see cref="T:System.ServiceModel.Channels.Message" /> being sent on the output channel.</param>
        /// <param name="timeout">The <see cref="T:System.TimeSpan" /> that specifies how long the send operation has to complete before timing out.</param>
        public void Send(Message message, TimeSpan timeout)
        {
            ThrowIfDisposedOrNotOpen();
            RemoteAddress.ApplyTo(message);

            using (NMS.ISession session = _connection.CreateSession())
            {
                IDestination destination = SessionUtil.GetDestination(session, Destination, DestinationType);
                using (IMessageProducer producer = session.CreateProducer(destination))
                {
                    producer.DeliveryMode = MsgDeliveryMode.Persistent;

                    ITextMessage request = session.CreateTextMessage(TranslateMessage(message));
                    producer.Send(request);
                    producer.Close();

                    Tracer.Info("Sending message:");
                    Tracer.Info(request.Text);
                }
            }
        }
示例#6
0
        /// <summary>
        /// Sends a message on the current output channel within a specified interval of time.
        /// </summary>
        /// <param name="message">The <see cref="T:System.ServiceModel.Channels.Message" /> being sent on the output channel.</param>
        /// <param name="timeout">The <see cref="T:System.TimeSpan" /> that specifies how long the send operation has to complete before timing out.</param>
        public void Send(Message message, TimeSpan timeout)
        {
            ThrowIfDisposedOrNotOpen();
            RemoteAddress.ApplyTo(message);

            NMS.ISession session = _connection.CreateSession();

            if (!session.Transacted)
            {
                using (session)
                {
                    DoSendMessageForSession(session, message);
                }
            }
            else
            {
                // we are inside a transaction, so we should defer session disposing until transaction ends
                session.TransactionCommittedListener  += SessionOnTransactionEndHandler;
                session.TransactionRolledBackListener += SessionOnTransactionEndHandler;
                DoSendMessageForSession(session, message);
            }
        }