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);
            }
        }
Exemplo n.º 2
0
        static public void ProcessEMSMessage(Message msg)
        {
            string separator1 = "\n*********************************************************************************************************************************";

            Console.WriteLine(separator1);
            string separator2 = "\n===================";

            try
            {
                Console.WriteLine(separator2 + " Message Received by the Thread \"" + Thread.CurrentThread.Name + "\" with Thread-Id " +

                                  Thread.CurrentThread.ManagedThreadId + "\n   " + msg.ToString());
                StackTrace stackTrace = new StackTrace();
                String     methodcallingsequence = ""; int methodnumber = 1;
                Session    ProducerSession = Messaging.EMS.Connection.EMSQueueConnection.connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);
                foreach (StackFrame sf in stackTrace.GetFrames())
                {
                    methodcallingsequence += "\n\t\t (" + methodnumber++.ToString() + ") " + sf.GetMethod().ToString();
                }
                if (msg.ReplyTo != null)
                {
                    string LogAndSend = "\n\nReplying with .NET runtime specific info :\n" +
                                        "\n\n MachineName: " + Environment.MachineName +
                                        "\n ReplyingProcessName: " + Process.GetCurrentProcess().ProcessName +
                                        "\n ReplyingProcessId: " + Process.GetCurrentProcess().Id +
                                        "\n ThreadName:\"" + Thread.CurrentThread.Name + "\"" +
                                        "\n ClientId: " + Messaging.EMS.Connection.EMSQueueConnection.connection.ClientID +
                                        "\n New Producer SessionId used for reply: " + ProducerSession.SessID +
                                        "\n MethodCallingSequence /*Most Recent at the top*/:\n" + methodcallingsequence
                    ;

                    TIBCO.EMS.TextMessage reply = ProducerSession.CreateTextMessage();
                    reply.Text    = LogAndSend;
                    reply.ReplyTo = msg.ReplyTo;

                    Messaging.EMS.Producers.Messageproducer.SendReplyMessage(reply, (TIBCO.EMS.Queue)msg.ReplyTo, ref ProducerSession);
                    Console.Write(separator2 + " This Reply has been sent:   " + LogAndSend + " \n\n ");
                }



                else
                {
                    Console.WriteLine(separator2 + " No reply sought for above  message as ReplyQueue is NUll . Threadname is \"" +

                                      Thread.CurrentThread.Name + "\"" +
                                      "\n\n MethodCallingSequence /*Most Recent at the top*/ :\n" + methodcallingsequence);
                }
                Console.WriteLine(separator1);
                msg.Acknowledge();
            }

            catch (EMSException e)
            {
                Console.Write("\n\n(******** Exception :\n" + e.StackTrace);
                msg.Acknowledge();
            }
        }
        public void StringConversion()
        {
            
            string content = "test";
            TextMessage message = new TextMessage(tibcoSession, content);

            Expect.Call(session.CreateTextMessage(content)).Return(message).Repeat.Once();
            string txt = message.Text;

            mocks.ReplayAll();


            Message msg = converter.ToMessage(content, session);

            Assert.AreEqual(content, converter.FromMessage(msg));

            mocks.VerifyAll();


        }
        public void RegisteredExceptionListenerIsInvokedOnException()
        {
            SimpleMessageConsumer messageConsumer = new SimpleMessageConsumer();

            ISession session = (ISession) mocks.CreateMock(typeof (ISession));
            Expect.Call(session.CreateQueue(DESTINATION_NAME)).Return(QUEUE_DESTINATION);
            Expect.Call(session.CreateConsumer(QUEUE_DESTINATION, null)).Return(messageConsumer);
            // an exception is thrown, so the rollback logic is being applied here...
            Expect.Call(session.Transacted).Return(false);

            IConnection connection = (IConnection)mocks.CreateMock(typeof(IConnection));
            //connection.ExceptionListener += container.OnException;
            connection.ExceptionListener = container;
            Expect.Call(connection.CreateSession(false, container.SessionAcknowledgeMode)).Return(session);
            connection.Start();
            
            IConnectionFactory connectionFactory = (IConnectionFactory) mocks.CreateMock(typeof (IConnectionFactory));
            Expect.Call(connectionFactory.CreateConnection()).Return(connection);

            EMSException theException = new EMSException(EXCEPTION_MESSAGE);

            IExceptionListener exceptionListener = (IExceptionListener) mocks.CreateMock(typeof (IExceptionListener));
            exceptionListener.OnException(theException);

            //IMessage message = (IMessage) mocks.CreateMock(typeof (IMessage));
            TextMessage message = new TextMessage(null, "hello");
            mocks.ReplayAll();


            container.ConnectionFactory = connectionFactory;
            container.DestinationName = DESTINATION_NAME;
            container.MessageListener = new BadSessionAwareMessageListener(theException);
            container.ExceptionListener = exceptionListener;
            container.AfterPropertiesSet();

            // manually trigger an Exception with the above bad MessageListener...
            messageConsumer.SendMessage(message);

            mocks.VerifyAll();
        }
Exemplo n.º 5
0
 /// <summary>
 /// Gets the type of the target given the message.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <returns>Type of the target</returns>
 protected virtual Type GetTargetType(TextMessage message)
 {
     return typeMapper.ToType(message.GetStringProperty(typeMapper.TypeIdFieldName));
 }
		public static void SendMessage(string name, string data)
		{
			var message = new TextMessage(new Session(), data);
			_destinations[name].OnMessage(message);
		}
Exemplo n.º 7
0
 private Type GetTargetType(TextMessage message)
 {
     return typeMapper.ToType(message.GetStringProperty(typeMapper.TypeIdFieldName));
 }
Exemplo n.º 8
0
 /// <summary> Extract a String from the given TextMessage.</summary>
 /// <param name="message">the message to convert
 /// </param>
 /// <returns> the resulting String
 /// </returns>
 /// <throws>  EMSException if thrown by EMS methods </throws>
 protected virtual string ExtractStringFromMessage(TextMessage message)
 {
     return message.Text;
 }
Exemplo n.º 9
0
 public TibcoTextMessage(TextMessage msg)
 {
     TibcoMsg = msg;
 }