Ejemplo n.º 1
0
 public void Send(string exchange, string routingKey, MessageCreatorDelegate messageCreatorDelegate)
 {
     AssertUtils.ArgumentNotNull(messageCreatorDelegate, "MessageCreatorDelegate must not be null");
     Execute <object>(delegate(IClientSession model)
     {
         DoSend(model, exchange, routingKey, null, messageCreatorDelegate);
         return(null);
     });
 }
Ejemplo n.º 2
0
        protected virtual void DoSend(IClientSession channel, string exchange, string routingKey, IMessageCreator messageCreator,
                                      MessageCreatorDelegate messageCreatorDelegate)
        {
            AssertUtils.IsTrue((messageCreator == null && messageCreatorDelegate != null) ||
                               (messageCreator != null && messageCreatorDelegate == null), "Must provide a MessageCreatorDelegate or IMessageCreator instance.");
            Message message;

            if (messageCreator != null)
            {
                message = messageCreator.CreateMessage();
            }
            else
            {
                message = messageCreatorDelegate();
            }
            if (exchange == null)
            {
                // try to send to default exchange
                exchange = this.exchange;
            }
            if (routingKey == null)
            {
                // try to send to default routing key
                routingKey = this.routingKey;
            }

            /*   org.apache.qpid.client.IMessage message = new org.apache.qpid.client.Message();
             *   message.ClearData();
             *  message.AppendData(Encoding.UTF8.GetBytes("That's all, folks!"));
             *  session.MessageTransfer("amq.direct", "routing_key", message);
             *  session.Sync();
             *
             */
            org.apache.qpid.client.IMessage qpidMessage = new org.apache.qpid.client.Message();
            qpidMessage.AppendData(message.Body);

            qpidMessage.DeliveryProperties = QpidUtils.ExtractDeliveryProperties(message);

            qpidMessage.DeliveryProperties.SetRoutingKey(routingKey);
            qpidMessage.DeliveryProperties.SetExchange(exchange);

            qpidMessage.DeliveryProperties.SetImmediate(this.immediatePublish);
            //TODO where to set mandetoryPublish?

            channel.MessageTransfer(exchange, routingKey, qpidMessage);
            channel.Sync();


            // TODO: should we be able to do (via wrapper) something like:
            // channel.getTransacted()?
            if (ChannelTransacted && ChannelLocallyTransacted(channel))
            {
                // Transacted channel created by this template -> commit.
                QpidUtils.CommitIfNecessary(channel);
            }
        }
Ejemplo n.º 3
0
 /// <summary> Send a message to the specified destination.
 /// The MessageCreator callback creates the message given a Session.
 /// </summary>
 /// <param name="destinationName">the name of the destination to send this message to
 /// (to be resolved to an actual destination by a DestinationResolver)
 /// </param>
 /// <param name="messageCreatorDelegate">delegate callback to create a message
 /// </param>
 /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
 public void SendWithDelegate(string destinationName, MessageCreatorDelegate messageCreatorDelegate)
 {
     Execute(new SendDestinationCallback(this, destinationName, messageCreatorDelegate), false);
 }
Ejemplo n.º 4
0
 /// <summary> Send a message to the default destination.
 /// <p>This will only work with a default destination specified!</p>
 /// </summary>
 /// <param name="messageCreatorDelegate">delegate callback to create a message
 /// </param>
 /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
 public void SendWithDelegate(MessageCreatorDelegate messageCreatorDelegate)
 {
     CheckDefaultDestination();
     if (DefaultDestination != null)
     {
         SendWithDelegate(DefaultDestination, messageCreatorDelegate);
     }
     else
     {
         SendWithDelegate(DefaultDestinationName, messageCreatorDelegate);
     }
 }
Ejemplo n.º 5
0
        /// <summary> Send the given EMS message.</summary>
        /// <param name="session">the EMS Session to operate on
        /// </param>
        /// <param name="destination">the EMS Destination to send to
        /// </param>
        /// <param name="messageCreator">callback to create a EMS Message
        /// </param>
        /// <param name="messageCreatorDelegate">delegate callback to create a EMS Message
        /// </param>
        /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
        protected internal virtual void DoSend(ISession session, Destination destination, IMessageCreator messageCreator,
                                               MessageCreatorDelegate messageCreatorDelegate)
        {


            IMessageProducer producer = CreateProducer(session, destination);            
            try
            {
                
                Message message;
                if (messageCreator != null)
                {
                    message = messageCreator.CreateMessage(session) ;
                }
                else {
                    message = messageCreatorDelegate(session);
                }
                if (logger.IsDebugEnabled)
                {
                    logger.Debug("Sending created message [" + message + "]");
                }
                DoSend(producer, message);

                // Check commit, avoid commit call is Session transaction is externally coordinated.
                if (session.Transacted && IsSessionLocallyTransacted(session))
                {
                    // Transacted session created by this template -> commit.
                    EmsUtils.CommitIfNecessary(session);
                }
            }
            finally
            {
                EmsUtils.CloseMessageProducer(producer);
            }
        }
Ejemplo n.º 6
0
        /*
        /// <summary>Create a EMS Connection via this template's ConnectionFactory.
        /// </summary>
        /// <remarks>If CacheJmsResource is true, then the connection 
        /// will be created upon the first invocation and will retrun the same
        /// connection on all subsequent calls.
        /// </remarks>
        /// <returns>A EMS Connection
        /// </returns>
        /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
        protected override IConnection CreateConnection()
        {
            if (CacheEmsResources)
            {
                if (emsResources.Connection == null)
                {
                    emsResources.Connection = ConnectionFactory.CreateConnection();
                }
                return emsResources.Connection;

            }
            else
            {
                return ConnectionFactory.CreateConnection();
            }
        }*/
        /*
        /// <summary> Create a EMS Session for the given Connection.
        /// </summary>
        /// <remarks>If CacheJmsResource is true, then the session 
        /// will be created upon the first invocation and will retrun the same
        /// session on all subsequent calls.
        /// </remarks>
        /// <param name="con">the EMS Connection to create a Session for
        /// </param>
        /// <returns> the new EMS Session
        /// </returns>
        /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
        protected override ISession CreateSession(IConnection con)
        {
            if (CacheEmsResources)
            {
                if (emsResources.Session == null)
                {
                    emsResources.Session = emsResources.Connection.CreateSession(SessionTransacted, SessionAcknowledgeMode);
                }
                return emsResources.Session;
            }
            else
            {
                return con.CreateSession(SessionTransacted, SessionAcknowledgeMode);
            }
        }*/

        /// <summary>
        /// Send the given message.
        /// </summary>
        /// <param name="session">The session to operate on.</param>
        /// <param name="destination">The destination to send to.</param>
        /// <param name="messageCreatorDelegate">The message creator delegate callback to create a Message.</param>
        protected internal virtual void DoSend(ISession session, Destination destination, MessageCreatorDelegate messageCreatorDelegate)
        {
            AssertUtils.ArgumentNotNull(messageCreatorDelegate, "IMessageCreatorDelegate must not be null");
            DoSend(session, destination, null, messageCreatorDelegate);
        }
Ejemplo n.º 7
0
 public SendDestinationCallback(EmsTemplate jmsTemplate, Destination destination, MessageCreatorDelegate messageCreatorDelegate)
 {
     this.jmsTemplate = jmsTemplate;
     this.destination = destination;
     this.messageCreatorDelegate = messageCreatorDelegate;
 }
Ejemplo n.º 8
0
 public SendDestinationCallback(EmsTemplate jmsTemplate, string destinationName, MessageCreatorDelegate messageCreatorDelegate)
 {
     this.jmsTemplate = jmsTemplate;
     this.destinationName = destinationName;
     this.messageCreatorDelegate = messageCreatorDelegate;
 }
Ejemplo n.º 9
0
 public void Send(string routingkey, MessageCreatorDelegate messageCreatorDelegate)
 {
     Send(this.exchange, routingKey, messageCreatorDelegate);
 }
Ejemplo n.º 10
0
 public void Send(MessageCreatorDelegate messageCreatorDelegate)
 {
     Send(this.exchange, this.routingKey, messageCreatorDelegate);
 }