OnMessage() public method

Standard JMS {@link MessageListener} entry point.

Delegates the message to the target listener method, with appropriate conversion of the message arguments

In case of an exception, the HandleListenerException method will be invoked. Note Does not support sending response messages based on result objects returned from listener methods. Use the ISessionAwareMessageListener entry point (typically through a Spring message listener container) for handling result objects as well.
public OnMessage ( IMessage message ) : void
message IMessage The incoming message.
return void
Exemplo n.º 1
0
        public void MessageContentsHandlerOverloadCalls()
        {
            int           numIterations = 10;
            IBytesMessage bytesMessage  = A.Fake <IBytesMessage>();
            ASCIIEncoding encoding      = new ASCIIEncoding();

            byte[] content = encoding.GetBytes("test");
            A.CallTo(() => bytesMessage.Content).Returns(content).NumberOfTimes(numIterations / 2);

            ITextMessage textMessage = A.Fake <ITextMessage>();

            A.CallTo(() => textMessage.Text).Returns(TEXT).NumberOfTimes(numIterations / 2);

            MessageContentsHandler handler = new MessageContentsHandler();

            MessageListenerAdapter adapter = new MessageListenerAdapter(handler);

            for (int i = 0; i < numIterations / 2; i++)
            {
                adapter.OnMessage(textMessage);
                adapter.OnMessage(bytesMessage);
            }

            Assert.AreEqual(numIterations / 2, handler.HandledByteArrayCount);
            Assert.AreEqual(numIterations / 2, handler.HandledStringCount);
        }
        public void MessageContentsHandlerOverloadCalls()
        {
            int           numIterations = 10;
            IBytesMessage bytesMessage  = mocks.StrictMock <IBytesMessage>();
            ASCIIEncoding encoding      = new ASCIIEncoding();

            byte[] content = encoding.GetBytes("test");
            Expect.Call(bytesMessage.Content).Return(content).Repeat.Times(numIterations / 2);

            ITextMessage textMessage = mocks.StrictMock <ITextMessage>();

            Expect.Call(textMessage.Text).Return(TEXT).Repeat.Times(numIterations / 2);

            MessageContentsHandler handler = new MessageContentsHandler();

            mocks.ReplayAll();

            MessageListenerAdapter adapter = new MessageListenerAdapter(handler);

            for (int i = 0; i < numIterations / 2; i++)
            {
                adapter.OnMessage(textMessage);
                adapter.OnMessage(bytesMessage);
            }
            Assert.AreEqual(numIterations / 2, handler.HandledByteArrayCount);
            Assert.AreEqual(numIterations / 2, handler.HandledStringCount);

            mocks.VerifyAll();
        }
        public void MessageContentsHandlerForTextMessage()
        {
            int numIterations = 10;
            ITextMessage message = mocks.StrictMock<ITextMessage>();
            Expect.Call(message.Text).Return(TEXT).Repeat.Times(numIterations);
            MessageContentsHandler handler = new MessageContentsHandler();
            mocks.ReplayAll();

            MessageListenerAdapter adapter = new MessageListenerAdapter(handler);
            for (int i = 0; i < numIterations; i++)
            {
                adapter.OnMessage(message);
            }
            Assert.AreEqual(numIterations, handler.HandledStringCount);

            mocks.VerifyAll();            
        }
Exemplo n.º 4
0
        public void MessageContentsHandlerForTextMessage()
        {
            int          numIterations = 10;
            ITextMessage message       = A.Fake <ITextMessage>();

            A.CallTo(() => message.Text).Returns(TEXT).NumberOfTimes(numIterations);
            MessageContentsHandler handler = new MessageContentsHandler();

            MessageListenerAdapter adapter = new MessageListenerAdapter(handler);

            for (int i = 0; i < numIterations; i++)
            {
                adapter.OnMessage(message);
            }

            Assert.AreEqual(numIterations, handler.HandledStringCount);
        }
        public void MessageContentsHandlerForBytesMessage()
        {
            int numIterations = 10;
            IBytesMessage message = mocks.StrictMock<IBytesMessage>();
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] content = encoding.GetBytes("test");
            Expect.Call(message.Content).Return(content).Repeat.Times(numIterations);
            MessageContentsHandler handler = new MessageContentsHandler();            
            mocks.ReplayAll();

            MessageListenerAdapter adapter = new MessageListenerAdapter(handler);
            for (int i = 0; i < numIterations; i++)
            {
                adapter.OnMessage(message);
            }
            Assert.AreEqual(numIterations, handler.HandledByteArrayCount);

            mocks.VerifyAll();
        }
Exemplo n.º 6
0
        public void MessageContentsHandlerForBytesMessage()
        {
            int           numIterations = 10;
            IBytesMessage message       = A.Fake <IBytesMessage>();
            ASCIIEncoding encoding      = new ASCIIEncoding();

            byte[] content = encoding.GetBytes("test");
            A.CallTo(() => message.Content).Returns(content).NumberOfTimes(numIterations);
            MessageContentsHandler handler = new MessageContentsHandler();

            MessageListenerAdapter adapter = new MessageListenerAdapter(handler);

            for (int i = 0; i < numIterations; i++)
            {
                adapter.OnMessage(message);
            }

            Assert.AreEqual(numIterations, handler.HandledByteArrayCount);
        }
        public void MessageContentsHandlerForTextMessage()
        {
            int          numIterations = 10;
            ITextMessage message       = mocks.StrictMock <ITextMessage>();

            Expect.Call(message.Text).Return(TEXT).Repeat.Times(numIterations);
            MessageContentsHandler handler = new MessageContentsHandler();

            mocks.ReplayAll();

            MessageListenerAdapter adapter = new MessageListenerAdapter(handler);

            for (int i = 0; i < numIterations; i++)
            {
                adapter.OnMessage(message);
            }
            Assert.AreEqual(numIterations, handler.HandledStringCount);

            mocks.VerifyAll();
        }
        public void MessageContentsHandlerForBytesMessage()
        {
            int           numIterations = 10;
            IBytesMessage message       = mocks.StrictMock <IBytesMessage>();
            ASCIIEncoding encoding      = new ASCIIEncoding();

            byte[] content = encoding.GetBytes("test");
            Expect.Call(message.Content).Return(content).Repeat.Times(numIterations);
            MessageContentsHandler handler = new MessageContentsHandler();

            mocks.ReplayAll();

            MessageListenerAdapter adapter = new MessageListenerAdapter(handler);

            for (int i = 0; i < numIterations; i++)
            {
                adapter.OnMessage(message);
            }
            Assert.AreEqual(numIterations, handler.HandledByteArrayCount);

            mocks.VerifyAll();
        }
        public void MessageContentsHandlerOverloadCalls()
        {
            int numIterations = 10;
            IBytesMessage bytesMessage = mocks.StrictMock<IBytesMessage>();
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] content = encoding.GetBytes("test");
            Expect.Call(bytesMessage.Content).Return(content).Repeat.Times(numIterations / 2);

            ITextMessage textMessage = mocks.StrictMock<ITextMessage>();
            Expect.Call(textMessage.Text).Return(TEXT).Repeat.Times(numIterations/2);

            MessageContentsHandler handler = new MessageContentsHandler();
            mocks.ReplayAll();

            MessageListenerAdapter adapter = new MessageListenerAdapter(handler);
            for (int i = 0; i < numIterations/2; i++)
            {
                adapter.OnMessage(textMessage);
                adapter.OnMessage(bytesMessage);
            }
            Assert.AreEqual(numIterations / 2, handler.HandledByteArrayCount);
            Assert.AreEqual(numIterations / 2, handler.HandledStringCount);

            mocks.VerifyAll();
        }