private void OnMessage(IReceiverLink receiver, global::Amqp.Message amqpMessage)
        {
            NmsMessage message;

            try
            {
                message = AmqpCodec.DecodeMessage(this, amqpMessage).AsMessage();
            }
            catch (Exception e)
            {
                Tracer.Error($"Error on transform: {e.Message}");

                // Mark message as undeliverable
                link.Modify(amqpMessage, true, true);
                return;
            }

            // Let the message do any final processing before sending it onto a consumer.
            // We could defer this to a later stage such as the NmsConnection or even in
            // the NmsMessageConsumer dispatch method if we needed to.
            message.OnDispatch();

            InboundMessageDispatch inboundMessageDispatch = new InboundMessageDispatch
            {
                Message      = message,
                ConsumerId   = info.Id,
                ConsumerInfo = info,
            };

            AddMessage(inboundMessageDispatch);

            IProviderListener providerListener = session.Connection.Provider.Listener;

            providerListener.OnInboundMessage(inboundMessageDispatch);
        }
Example #2
0
        public void TestMethod_MessageDeliveryModify()
        {
            string     testName   = "MessageDeliveryModify";
            Connection connection = new Connection(testTarget.Address);
            Session    session    = new Session(connection);
            SenderLink sender     = new SenderLink(session, "sender-" + testName, testTarget.Path);
            Message    message    = new Message("msg modify");

            sender.Send(message, null, null);

            ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, testTarget.Path);

            message = receiver.Receive();
            MessageDelivery messageDelivery = message.GetDelivery();

            message.Dispose();
            receiver.Modify(messageDelivery, true);
            connection.Close();
        }
Example #3
0
        public void TestMethod_ModifyMessage()
        {
            string     testName   = "ModifyMessage";
            const int  nMsgs      = 20;
            Connection connection = new Connection(testTarget.Address);
            Session    session    = new Session(connection);

            SenderLink sender = new SenderLink(session, "sender-" + testName, testTarget.Path);

            for (int i = 0; i < nMsgs; ++i)
            {
                Message message = new Message();
                message.MessageAnnotations = new MessageAnnotations();
                message.MessageAnnotations[(Symbol)"a1"] = 12345L;
                message.Properties = new Properties()
                {
                    MessageId = "msg" + i
                };
                message.ApplicationProperties       = new ApplicationProperties();
                message.ApplicationProperties["sn"] = i;
                sender.Send(message, null, null);
            }

            ReceiverLink receiver = new ReceiverLink(session, "receiver-" + testName, testTarget.Path);

            for (int i = 0; i < nMsgs; ++i)
            {
                Message message = receiver.Receive();
                Trace.WriteLine(TraceLevel.Verbose, "receive: {0}", message.Properties.MessageId);
                if (i % 2 == 0)
                {
                    receiver.Accept(message);
                }
                else
                {
                    receiver.Modify(message, true, false, new Fields()
                    {
                        { (Symbol)"reason", "app offline" }
                    });
                }
            }
            receiver.Close();

            ReceiverLink receiver2 = new ReceiverLink(session, "receiver2-" + testName, testTarget.Path);

            for (int i = 0; i < nMsgs / 2; ++i)
            {
                Message message = receiver2.Receive();
                Trace.WriteLine(TraceLevel.Verbose, "receive: {0}", message.Properties.MessageId);
                Assert.IsTrue(message.Header != null, "header is null");
                Assert.IsTrue(message.Header.DeliveryCount > 0, "delivery-count is 0");
                Assert.IsTrue(message.MessageAnnotations != null, "annotation is null");
                Assert.IsTrue(message.MessageAnnotations[(Symbol)"a1"].Equals(12345L));
                Assert.IsTrue(message.MessageAnnotations[(Symbol)"reason"].Equals("app offline"));
                receiver2.Accept(message);
            }

            receiver2.Close();
            sender.Close();
            session.Close();
            connection.Close();
        }