コード例 #1
0
ファイル: MessageConsumer.cs プロジェクト: pl89/nms-amqp
        protected void OnInboundMessage(IReceiverLink link, Amqp.Message message)
        {
            Message.Message msg = null;
            try
            {
                IMessage nmsMessage = Message.AMQP.AMQPMessageBuilder.CreateProviderMessage(this, message);
                msg = nmsMessage as Message.Message;
                if (
                    Session.AcknowledgementMode.Equals(AcknowledgementMode.AutoAcknowledge) ||
                    Session.AcknowledgementMode.Equals(AcknowledgementMode.ClientAcknowledge)
                    )
                {
                    msg.GetMessageCloak().AckHandler = new Message.MessageAcknowledgementHandler(this, msg);
                }
            }
            catch (Exception e)
            {
                this.Session.OnException(e);
            }

            if (msg != null)
            {
                transportMsgCount++;

                SendForDelivery(new MessageDelivery(msg));
            }
        }
コード例 #2
0
ファイル: MessageConsumer.cs プロジェクト: pl89/nms-amqp
 private void AckReleased(IMessageDelivery delivery)
 {
     Message.Message nmsMessage = delivery.Message;
     Tracer.DebugFormat("Consumer {0} Acking Released for Message {1} ", ConsumerId, nmsMessage.NMSMessageId);
     Amqp.Message amqpMessage = (nmsMessage.GetMessageCloak() as Message.AMQP.AMQPMessageCloak).AMQPMessage;
     this.Link.Release(amqpMessage);
 }
コード例 #3
0
ファイル: MessageConsumer.cs プロジェクト: pl89/nms-amqp
 private void AckConsumed(IMessageDelivery delivery)
 {
     Message.Message nmsMessage = delivery.Message;
     Tracer.DebugFormat("Consumer {0} Acking Accepted for Message {1} ", ConsumerId, nmsMessage.NMSMessageId);
     delivered.Remove(delivery);
     Amqp.Message amqpMessage = (nmsMessage.GetMessageCloak() as Message.AMQP.AMQPMessageCloak).AMQPMessage;
     this.Link.Accept(amqpMessage);
 }
コード例 #4
0
ファイル: MessageConsumer.cs プロジェクト: pl89/nms-amqp
 private void AckModified(IMessageDelivery delivery, bool deliveryFailed, bool undeliverableHere = false)
 {
     Message.Message nmsMessage = delivery.Message;
     Tracer.DebugFormat("Consumer {0} Acking Modified for Message {1}{2}{3}.", ConsumerId, nmsMessage.NMSMessageId,
                        deliveryFailed ? " Delivery Failed" : "",
                        undeliverableHere ? " Undeliveryable Here" : "");
     Amqp.Message amqpMessage = (nmsMessage.GetMessageCloak() as Message.AMQP.AMQPMessageCloak).AMQPMessage;
     //TODO use Link.Modified from amqpNetLite 2.0.0
     this.Link.Modify(amqpMessage, deliveryFailed, undeliverableHere, null);
 }
コード例 #5
0
ファイル: MessageConsumer.cs プロジェクト: pl89/nms-amqp
        private bool IsMessageRedeliveryExceeded(IMessageDelivery delivery)
        {
            Message.Message   message = delivery.Message;
            IRedeliveryPolicy policy  = this.Session.Connection.RedeliveryPolicy;

            if (policy != null && policy.MaximumRedeliveries >= 0)
            {
                IMessageCloak msgCloak = message.GetMessageCloak();
                return(msgCloak.RedeliveryCount > policy.MaximumRedeliveries);
            }
            return(false);
        }
コード例 #6
0
ファイル: MessageProducer.cs プロジェクト: pl89/nms-amqp
        protected void DoSend(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
        {
            this.Attach();
            bool sendSync = deliveryMode.Equals(MsgDeliveryMode.Persistent);

            if (destination.IsTemporary && (destination as TemporaryDestination).IsDeleted)
            {
                throw new InvalidDestinationException("Can not send message on deleted temporary topic.");
            }
            message.NMSDestination  = destination;
            message.NMSDeliveryMode = deliveryMode;
            message.NMSPriority     = priority;
            // If there is  timeToLive, set it before setting NMSTimestamp as timeToLive
            // is required to calculate absolute expiry time.
            // TBD: If the messageProducer has a non-default timeToLive and the message
            // already has a timeToLive set by application, which should take precedence, this
            // code overwrites the message TimeToLive in this case but not if the producer TimeToLive
            // is the default ...
            if (timeToLive != NMSConstants.defaultTimeToLive)
            {
                message.NMSTimeToLive = timeToLive;
            }
            if (!DisableMessageTimestamp)
            {
                message.NMSTimestamp = DateTime.UtcNow;
            }


            if (!DisableMessageID)
            {
                message.NMSMessageId = MessageIdGenerator.GenerateId().ToString();
            }

            Amqp.Message amqpmsg = null;
            if (message is Message.Message)
            {
                Message.Message copy = (message as Message.Message).Copy();
                copy.NMSDestination = DestinationTransformation.Transform(Session.Connection, destination);
                PrepareMessageForSend(copy);
                IMessageCloak cloak = copy.GetMessageCloak();
                if (cloak is AMQPMessageCloak)
                {
                    amqpmsg = (cloak as AMQPMessageCloak).AMQPMessage;
                }
            }
            else
            {
                Message.Message nmsmsg = this.Session.Connection.TransformFactory.TransformMessage <Message.Message>(message);
                PrepareMessageForSend(nmsmsg);
                IMessageCloak cloak = nmsmsg.GetMessageCloak().Copy();
                if (cloak is AMQPMessageCloak)
                {
                    amqpmsg = (cloak as AMQPMessageCloak).AMQPMessage;
                }
            }



            if (amqpmsg != null)
            {
                if (Tracer.IsDebugEnabled)
                {
                    Tracer.DebugFormat("Sending message : {0}", message.ToString());
                }

                if (sendSync)
                {
                    DoAMQPSendSync(amqpmsg, this.RequestTimeout);
                }
                else
                {
                    DoAMQPSendAsync(amqpmsg, HandleAsyncAMQPMessageOutcome);
                }
            }
        }