Ejemplo n.º 1
0
        public Producer()
        {
            string serverUrl = ConfigurationManager.AppSettings["serverUrl"];
            string userName = ConfigurationManager.AppSettings["userName"];
            string password = ConfigurationManager.AppSettings["password"];
            string topicName = ConfigurationManager.AppSettings["avnTopicName"];

            string inputQueueName = ConfigurationManager.AppSettings["inputQueueName"];

            try
            {
                ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl);
                connection = factory.CreateConnection(userName, password);
                // create the session
                session = connection.CreateSession(false, Session.NO_ACKNOWLEDGE);
                // create the destination
                destination = session.CreateQueue(inputQueueName);

                //destination = session.CreateTopic(topicName);

                // create the producer
                msgProducer = session.CreateProducer(null);
                msg = session.CreateTextMessage();
            }
            catch (Exception ex)
            {
                Console.WriteLine("EMS Error: {0} {1}", ex.Message, ex.InnerException.Message);
            }
        }
Ejemplo n.º 2
0
        public void Reconnect()
        {
            if (Session != null && !Session.IsClosed)
                Session.Close();

            Provider.Connect();
            Session = Provider.Connection.CreateSession(false, SessionMode.AutoAcknowledge);
            Destination = Session.CreateQueue(QueueName);
            AfterReconnect();
        }
Ejemplo n.º 3
0
        public AsyncMessageConsumerUsingMessageListener(String QueueName, int NoOfSessions)
        {
            EMSQueueConnection.connection.Stop(); /* Iffy if multiple clients are using the conn.  */
            this.QueueName    = QueueName;
            this.NoOfSessions = NoOfSessions;

            TIBCO.EMS.Session         session     = null;
            TIBCO.EMS.MessageConsumer msgConsumer = null;
            TIBCO.EMS.Destination     destination = null;

            try
            {
                for (int i = 0; i < NoOfSessions; i++)
                {
                    /*
                     * Create a new session which in turn creates a thread interanlly .
                     * Ack mode is hard coded for now , see no possibulty for  it being other than CLient_ack*/
                    session = EMSQueueConnection.connection.CreateSession(false, Session.CLIENT_ACKNOWLEDGE);

                    // create the consumer
                    if (destination == null)
                    {
                        destination = session.CreateQueue(QueueName);
                    }
                    msgConsumer = session.CreateConsumer(destination);

                    // set the message listener
                    msgConsumer.MessageListener = this;

                    /*
                     * Console.WriteLine("\n Subscribing to destination: " + QueueName);Console.WriteLine("************************************************\n ThreadName:"
                     + System.Threading.Thread.CurrentThread.Name + "\n  Session:" + session.ToString()
                     +
                     + "\n  SessionID:" + session.SessID + "\n  Connection:" + session.Connection.ToString() +
                     + "\n  MessageConsumer:" + msgConsumer.ToString()  );*/
                }

                EMSQueueConnection.connection.Start();
                // Start pub-sub messages
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Exception in AsyncMsgConsumer: " + e.Message);
                Console.Error.WriteLine(e.StackTrace);
            }
        }
Ejemplo n.º 4
0
 public IMessageConsumer CreateConsumer(Destination dest, string messageSelector, bool noLocal)
 {
     return new EmsMessageConsumer(nativeSession.CreateConsumer(dest, messageSelector, noLocal));
 }
Ejemplo n.º 5
0
 public IMessageProducer CreateProducer(Destination dest)
 {
     return new EmsMessageProducer(nativeSession.CreateProducer(dest));
 }
Ejemplo n.º 6
0
 public IMessageConsumer CreateConsumer(Destination destination, string selector)
 {
     return new TestMessageConsumer();
 }
Ejemplo n.º 7
0
 public IMessageProducer CreateProducer(Destination dest)
 {
     return new TestMessageProducer();
 }
Ejemplo n.º 8
0
 public void Send(Destination destination, Message message)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 9
0
 /// <summary> Send the given object to the specified destination, converting the object
 /// to a EMS message with a configured IMessageConverter. The IMessagePostProcessor
 /// callback allows for modification of the message after conversion.
 /// </summary>
 /// <param name="destination">the destination to send this message to
 /// </param>
 /// <param name="message">the object to convert to a message
 /// </param>
 /// <param name="postProcessor">the callback to modify the message
 /// </param>
 /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
 public void ConvertAndSend(Destination destination, object message, IMessagePostProcessor postProcessor)
 {
     CheckMessageConverter();
     Send(destination, new ConvertAndSendMessageCreator(this, message, postProcessor));
     
 }
Ejemplo n.º 10
0
 /// <summary> Send a message to the specified destination.
 /// The MessageCreator callback creates the message given a Session.
 /// </summary>
 /// <param name="destination">the destination to send this message to
 /// </param>
 /// <param name="messageCreator">callback to create a message
 /// </param>
 /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
 public void Send(Destination destination, IMessageCreator messageCreator)
 {
     
     Execute(new SendDestinationCallback(this, destination, messageCreator), false);
 }
Ejemplo n.º 11
0
 public SendDestinationCallback(EmsTemplate jmsTemplate, Destination destination, IMessageCreator messageCreator)
 {
     this.jmsTemplate = jmsTemplate;
     this.destination = destination;
     this.messageCreator = messageCreator;
 }
Ejemplo n.º 12
0
 public ReceiveSelectedCallback(EmsTemplate jmsTemplate,
                    Destination destination,
                    string messageSelector)
 {
     this.jmsTemplate = jmsTemplate;
     this.destination = destination;
     this.messageSelector = messageSelector;
 }
Ejemplo n.º 13
0
 public ReceiveCallback(EmsTemplate jmsTemplate, Destination destination)
 {
     this.jmsTemplate = jmsTemplate;
     this.destination = destination;
 }
Ejemplo n.º 14
0
 /// <summary> Receive a message synchronously from the specified destination, but only
 /// wait up to a specified time for delivery. Convert the message into an
 /// object with a configured IMessageConverter.
 /// <p>This method should be used carefully, since it will block the thread
 /// until the message becomes available or until the timeout value is exceeded.</p>
 /// </summary>
 /// <param name="destination">the destination to receive a message from
 /// </param>
 /// <param name="messageSelector">the EMS message selector expression (or <code>null</code> if none).
 /// See the EMS specification for a detailed definition of selector expressions.
 /// </param>
 /// <returns> the message produced for the consumer or <code>null</code> if the timeout expires.
 /// </returns>
 /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
 public object ReceiveSelectedAndConvert(Destination destination, string messageSelector)
 {
     CheckMessageConverter();
     return DoConvertFromMessage(ReceiveSelected(destination, messageSelector));
 }
Ejemplo n.º 15
0
 /// <summary> Receive a message synchronously from the specified destination, but only
 /// wait up to a specified time for delivery. Convert the message into an
 /// object with a configured IMessageConverter.
 /// <p>This method should be used carefully, since it will block the thread
 /// until the message becomes available or until the timeout value is exceeded.</p>
 /// </summary>
 /// <param name="destination">the destination to receive a message from
 /// </param>
 /// <returns> the message produced for the consumer or <code>null</code> if the timeout expires.
 /// </returns>
 /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
 public object ReceiveAndConvert(Destination destination)
 {
     CheckMessageConverter();
     return DoConvertFromMessage(Receive(destination));
 }
Ejemplo n.º 16
0
 /// <summary> Send a message to the specified destination.
 /// The MessageCreator callback creates the message given a Session.
 /// </summary>
 /// <param name="destination">the destination to send this message to
 /// </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(Destination destination, MessageCreatorDelegate messageCreatorDelegate)
 {
     Execute(new SendDestinationCallback(this, destination, messageCreatorDelegate), false);
 }
Ejemplo n.º 17
0
 public SendDestinationCallback(EmsTemplate jmsTemplate, Destination destination, MessageCreatorDelegate messageCreatorDelegate)
 {
     this.jmsTemplate = jmsTemplate;
     this.destination = destination;
     this.messageCreatorDelegate = messageCreatorDelegate;
 }
Ejemplo n.º 18
0
 /// <summary> Send the given object to the specified destination, converting the object
 /// to a EMS message with a configured IMessageConverter.
 /// </summary>
 /// <param name="destination">the destination to send this message to
 /// </param>
 /// <param name="message">the object to convert to a message
 /// </param>
 /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
 public void ConvertAndSend(Destination destination, object message)
 {
     CheckMessageConverter();
     Send(destination, new SimpleMessageCreator(this, message));
 }
Ejemplo n.º 19
0
 public object DoInEms(ISession session)
 {
     if (destination == null)
     {
         destination = jmsTemplate.ResolveDestinationName(session, destinationName);
     }
     if (messageCreator != null)
     {
         jmsTemplate.DoSend(session, destination, messageCreator);
     }
     else
     {
         jmsTemplate.DoSend(session, destination, messageCreatorDelegate);
     }
     return null;
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Opens if is not initialized yet, otherwise just returns with no action.
        /// </summary>
        public void Open()
        {
            if (!initialized)
            {

                ValidateQueueConfiguration();

                try
                {
                    factory = new ConnectionFactory(ServerConfig.Url, ServerConfig.ClientId);
                }
                catch (EMSException e)
                {
                    Log.TraceData(Log.Source, TraceEventType.Error, 15000, "URL/Client ID is wrong. " + e.ToString());
                    throw;
                }

                IConfigurationValueProvider configProvider = new SingleTagSectionConfigurationProvider(this.ServerConfig.AuthenticationSectionName);

                try
                {
                    connection = factory.CreateConnection(configProvider["userName"], configProvider["password"]);
                }
                catch (EMSException e)
                {
                    Log.TraceData(Log.Source, TraceEventType.Error, 15001, "Connection to ems server failed! " + e.ToString());
                    throw;
                }

                try
                {
                    session = connection.CreateSession(this.sessionConfig.IsTransactional, sessionConfig.Mode);

                }
                catch (EMSException e)
                {
                    Log.TraceData(Log.Source, TraceEventType.Error, 15002, "Error during session creation. " + e.ToString());
                    throw;
                }

                try
                {
                    destination =
                        CreateDestination(session, queueConfig.Name, queueConfig.Type);

                    consumer =
                        session.CreateConsumer(destination, queueConfig.MessageSelector,
                                               queueConfig.NoLocal);

                    connection.Start();
                }
                catch (EMSException e)
                {
                    Log.TraceData(Log.Source, TraceEventType.Error, 15003, "Queue initialization error. " + e);
                    throw;
                }
                initialized = true;
            }
        }
Ejemplo n.º 21
0
 /// <summary> Create a EMS MessageProducer for the given Session and Destination,
 /// configuring it to disable message ids and/or timestamps (if necessary).
 /// <p>Delegates to <code>doCreateProducer</code> for creation of the raw
 /// EMS MessageProducer</p>
 /// </summary>
 /// <param name="session">the EMS Session to create a MessageProducer for
 /// </param>
 /// <param name="destination">the EMS Destination to create a MessageProducer for
 /// </param>
 /// <returns> the new EMS MessageProducer
 /// </returns>
 /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
 /// <seealso cref="DoCreateProducer">
 /// </seealso>
 /// <seealso cref="MessageIdEnabled">
 /// </seealso>
 /// <seealso cref="MessageTimestampEnabled">
 /// </seealso>
 protected virtual IMessageProducer CreateProducer(ISession session, Destination destination)
 {
     IMessageProducer producer = DoCreateProducer(session, destination);
     if (!MessageIdEnabled)
     {
         producer.DisableMessageID = true;
     }
     if (!MessageTimestampEnabled)
     {
         producer.DisableMessageTimestamp = true;
     }
     return producer;
 }
Ejemplo n.º 22
0
 public void Send(Destination dest, Message message, MessageDeliveryMode deliveryMode, int priority, long timeToLive)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 23
0
        /// <summary> Create a raw EMS MessageProducer for the given Session and Destination.
        /// </summary>
        /// <remarks>If CacheJmsResource is true, then the producer 
        /// will be created upon the first invocation and will retrun the same
        /// producer (per destination) on all subsequent calls.
        /// </remarks>
        /// <param name="session">the EMS Session to create a MessageProducer for
        /// </param>
        /// <param name="destination">the EMS Destination to create a MessageProducer for
        /// </param>
        /// <returns> the new EMS MessageProducer
        /// </returns>
        /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
        protected virtual IMessageProducer DoCreateProducer(ISession session, Destination destination)
        {
            return session.CreateProducer(destination);
            /*
            if (CacheEmsResources)
            {
                if (destination == null)
                {
                    if (emsResources.UnspecifiedDestinationMessageProducer == null)
                    {
                        emsResources.UnspecifiedDestinationMessageProducer = session.CreateProducer(destination);
                    }
                    return emsResources.UnspecifiedDestinationMessageProducer;
                }
                IMessageProducer producer = (IMessageProducer)emsResources.Producers[destination];
                if (producer != null)
                {
                    #region Logging

                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug("Found cached MessageProducer for destination [" + destination + "]");
                    }

                    #endregion
                }
                else
                {
                    producer = session.CreateProducer(destination);
                    emsResources.Producers.Add(destination, producer);
                    #region Logging

                    if (logger.IsDebugEnabled)
                    {
                        logger.Debug("Created cached MessageProducer for destination [" + destination + "]");
                    }

                    #endregion
                }
                return producer;
            }
            else
            {
                return session.CreateProducer(destination);
            }*/      
        }
Ejemplo n.º 24
0
 public IMessageConsumer CreateConsumer(Destination destination)
 {
     return new TestMessageConsumer();
 }
Ejemplo n.º 25
0
 /// <summary> Create a EMS MessageConsumer for the given Session and Destination.
 /// </summary>
 /// <param name="session">the EMS Session to create a MessageConsumer for
 /// </param>
 /// <param name="destination">the EMS Destination to create a MessageConsumer for
 /// </param>
 /// <param name="messageSelector">the message selector for this consumer (can be <code>null</code>)
 /// </param>
 /// <returns> the new EMS MessageConsumer
 /// </returns>
 /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
 protected virtual IMessageConsumer CreateConsumer(ISession session, Destination destination,
                                                   string messageSelector)
 {
     // Only pass in the NoLocal flag in case of a Topic:
     // Some EMS providers, such as WebSphere MQ 6.0, throw IllegalStateException
     // in case of the NoLocal flag being specified for a Queue.
     if (PubSubDomain)
     {
         return session.CreateConsumer(destination, messageSelector, PubSubNoLocal);
     }
     else
     {
         return session.CreateConsumer(destination, messageSelector);
     }
 }
Ejemplo n.º 26
0
 public IMessageConsumer CreateConsumer(Destination dest, string messageSelector, bool noLocal)
 {
     return new TestMessageConsumer();
 }
Ejemplo n.º 27
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.º 28
0
 public IMessageConsumer CreateConsumer(Destination dest)
 {
     return new EmsMessageConsumer(nativeSession.CreateConsumer(dest));
     
 }
Ejemplo n.º 29
0
 /// <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="messageCreator">The message creator callback to create a Message.</param>
 protected internal virtual void DoSend(ISession session, Destination destination, IMessageCreator messageCreator)
 {
     AssertUtils.ArgumentNotNull(messageCreator, "IMessageCreator must not be null");
     DoSend(session, destination, messageCreator, null);
 }
 /// <summary>
 /// Creates a MessageConsumer for the given Session and Destination.
 /// </summary>
 /// <param name="session">The session to create a MessageConsumer for.</param>
 /// <param name="destination">The destination to create a MessageConsumer for.</param>
 /// <returns>The new MessageConsumer</returns>
 protected IMessageConsumer CreateConsumer(ISession session, Destination destination)
 {
     // Only pass in the NoLocal flag in case of a Topic:
     // Some EMS providers, such as WebSphere MQ 6.0, throw IllegalStateException
     // in case of the NoLocal flag being specified for a Queue.
     if (PubSubDomain)
     {
         if (SubscriptionDurable && destination is Topic)
         {
             return session.CreateDurableSubscriber(
                 (Topic) destination, DurableSubscriptionName, MessageSelector, PubSubNoLocal);
         }
         else
         {
             return session.CreateConsumer(destination, MessageSelector, PubSubNoLocal);
         }
     }
     else
     {
         return session.CreateConsumer(destination, MessageSelector);
     }
 }
Ejemplo n.º 31
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);
            }
        }