Beispiel #1
0
        public async Task <IMessageProducer> CreateProducerAsync(IDestination destination)
        {
            var producer = new NmsMessageProducer(GetNextProducerId(), this, destination);
            await producer.Init().Await();

            return(producer);
        }
        public IMessageProducer CreateProducer(IDestination destination)
        {
            NmsMessageProducer messageProducer = new NmsMessageProducer(producerIdGenerator.GenerateId(), this, destination);

            messageProducer.Init().ConfigureAwait(false).GetAwaiter().GetResult();
            producers.TryAdd(messageProducer.Info.Id, messageProducer);
            return(messageProducer);
        }
Beispiel #3
0
 /**
  * Create a new JMSProducer instance.
  *
  * The producer is backed by the given Session object and uses the shared MessageProducer
  * instance to send all of its messages.
  *
  * @param session
  *      The Session that created this JMSProducer
  * @param producer
  *      The shared MessageProducer owned by the parent Session.
  */
 public NmsProducer(ISession session, NmsMessageProducer producer)
 {
     this.session  = session;
     this.producer = producer;
 }
Beispiel #4
0
 public void Remove(NmsMessageProducer messageProducer)
 {
     producers.TryRemove(messageProducer.Info.Id, out messageProducer);
 }
Beispiel #5
0
        public void Send(NmsMessageProducer producer, IDestination destination, IMessage original, MsgDeliveryMode deliveryMode,
                         MsgPriority priority, TimeSpan timeToLive, bool disableMessageId, bool disableMessageTimestamp)
        {
            if (destination == null)
            {
                throw new InvalidDestinationException("Destination must not be null");
            }

            if (original == null)
            {
                throw new MessageFormatException("Message must not be null");
            }

            NmsMessage outbound = null;

            original.NMSDeliveryMode = deliveryMode;
            original.NMSPriority     = priority;
            original.NMSRedelivered  = false;
            original.NMSDestination  = destination;

            bool isNmsMessage = original is NmsMessage;

            DateTime timeStamp = DateTime.UtcNow;

            bool hasTTL = timeToLive > TimeSpan.Zero;

            if (!disableMessageTimestamp)
            {
                original.NMSTimestamp = timeStamp;
            }
            else
            {
                original.NMSTimestamp = DateTime.MinValue;
            }

            if (!disableMessageId)
            {
                original.NMSMessageId = producer.MessageIdGenerator.GenerateId().ToString();
            }
            else
            {
                original.NMSMessageId = null;
            }

            if (isNmsMessage)
            {
                outbound = (NmsMessage)original;
            }
            else
            {
                outbound = NmsMessageTransformation.TransformMessage(Connection.MessageFactory, original);
            }

            if (hasTTL)
            {
                outbound.Facade.Expiration = timeStamp + timeToLive;
            }
            else
            {
                outbound.Facade.Expiration = DateTime.MinValue;
            }

            outbound.OnSend(timeToLive);

            bool sync = deliveryMode == MsgDeliveryMode.Persistent;

            Connection.Send(new OutboundMessageDispatch
            {
                Message      = outbound,
                ProducerId   = producer.Info.Id,
                ProducerInfo = producer.Info,
                SendAsync    = !sync
            }).ConfigureAwait(false).GetAwaiter().GetResult();
        }