コード例 #1
0
        /// <summary>
        /// Waits for a message on the preconfigured queue.
        /// Blocks until a message in received or the connection is closed.
        /// </summary>
        /// <returns>Read message. Null if the connection is closed.</returns>
        public string Receive()
        {
            ITextMessage message = null;

            try
            {
                logger.Info("wait for new message");
                message = consumer.Receive() as ITextMessage;
                logger.Info("recieved new message. Processing...");
            }
            catch (Exception e)
            {
                logger.WarnFormat("Exception caught in receivethread. Maybe OpenEngSB terminated - {0} ({1}).", e.Message, e.GetType().Name);
                Handling.Changed += delegate(object[] obj)
                {
                    return(Receive());
                };
                return(Handling.HandleException(e).ToString());
            }

            if (message == null)
            {
                return(null);
            }

            logger.DebugFormat("recieved message: {0}", message.Text);
            return(message.Text);
        }
コード例 #2
0
 /// <summary>
 /// Send a string over NMS and defines the replyTo field
 /// </summary>
 /// <param name="text">Text to send</param>
 /// <param name="replyTo">Reply destination</param>
 public void Send(string text, String queueName)
 {
     try
     {
         ITextMessage message = Session.CreateTextMessage(text);
         message.NMSReplyTo = Session.GetQueue(queueName);
         producer.Send(message);
     }
     catch (Exception ex)
     {
         Handling.Changed += delegate(object[] obj)
         {
             Send(obj[0].ToString(), obj[1].ToString());
             return(null);
         };
         Handling.HandleException(ex, text, queueName);
     }
 }
コード例 #3
0
        /// <summary>
        /// Send a string over NMS.
        /// </summary>
        /// <param name="text">Text to send</param>
        /// <param name="receiver">Queue name on server side</param>
        public void Send(string text)
        {
            try
            {
                ITextMessage message = Session.CreateTextMessage(text);
                producer.Send(message);
            }
            catch (Exception ex)
            {
                Handling.Changed += delegate(object[] obj)
                {
                    Send(obj[0].ToString());
                    return(null);
                };

                Handling.HandleException(ex, text);
            }
        }
コード例 #4
0
ファイル: JMSPort.cs プロジェクト: frenzqse/loom-csharp
        /// <summary>
        /// Configurate the Connection
        /// </summary>
        /// <param name="destination">Destionation</param>
        protected void Configure()
        {
            if (DoesConnectionExists())
            {
                return;
            }

            try
            {
                JmsDestination dest          = new JmsDestination(stringDestination);
                Uri            connectionUri = new Uri(dest.Host);
                Factory = new Apache.NMS.ActiveMQ.ConnectionFactory(dest.Host);
                IConnection connection = Factory.CreateConnection();
                connection.Start();
                if (connections.ContainsKey(ConnectorId))
                {
                    connections[ConnectorId].Add(stringDestination, connection);
                }
                else
                {
                    IDictionary <String, IConnection> tmp = new Dictionary <String, IConnection>();
                    tmp.Add(stringDestination, connection);
                    connections.Add(ConnectorId, tmp);
                }
            }
            catch (Exception ex)
            {
                // This allows it to invoke the method "Listen" again
                // The exception handler (if configured) invokes Changed
                // that will be forwarded to delegate (Object[] notUsed)
                Handling.Changed += delegate(Object[] notUsed)
                {
                    Configure();
                    return(null);
                };
                Handling.HandleException(ex);
            }
        }