Package javax.jms

Examples of javax.jms.StreamMessage


        MessageProducer mandatoryProducer = producerSession.createProducer(queue);

        // Third test - should be routed
        _logger.info("Sending isBound message");
        StreamMessage msg = producerSession.createStreamMessage();

        msg.setStringProperty("F1000", "1");

        msg.writeByte((byte) 42);

        mandatoryProducer.send(msg);

        _logger.info("Starting consumer connection");
        con.start();

        StreamMessage msg2 = (StreamMessage) consumer.receive(2000);
        assertNotNull(msg2);

        msg2.readByte();
        try
        {
            msg2.readByte();
        }
        catch (Exception e)
        {
            assertTrue("Expected MessageEOFException: " + e, e instanceof MessageEOFException);
        }
View Full Code Here


        consumer.setMessageListener(new MessageListener()
            {

                public void onMessage(Message message)
                {
                    StreamMessage sm = (StreamMessage) message;
                    try
                    {
                        sm.clearBody();
                        sm.writeString("dfgjshfslfjshflsjfdlsjfhdsljkfhdsljkfhsd");
                    }
                    catch (JMSException e)
                    {
                        _logger.error("Error when writing large string to received msg: " + e, e);
                        fail("Error when writing large string to received msg" + e);
                    }
                }
            });

        Connection con2 = (AMQConnection) getConnection("guest", "guest");
        AMQSession producerSession = (AMQSession) con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        MessageProducer mandatoryProducer = producerSession.createProducer(queue);
        con.start();
        StreamMessage sm = producerSession.createStreamMessage();
        sm.writeInt(42);
        mandatoryProducer.send(sm);
        Thread.sleep(2000);
        con.close();
        con2.close();
    }
View Full Code Here

        MessageConsumer consumer = session.createConsumer(destination);
        MessageProducer producer = session.createProducer(destination);

        // Send the message.
        {
            StreamMessage message = session.createStreamMessage();
            message.writeString("This is a test to see how it works.");
            producer.send(message);
        }

        // Check the message.
        {
            StreamMessage message = (StreamMessage)consumer.receive(1000);
            assertNotNull(message);

            // Invalid conversion should throw exception and not move the stream
            // position.
            try {
                message.readByte();
                fail("Should have received NumberFormatException");
            } catch (NumberFormatException e) {
            }

            assertEquals("This is a test to see how it works.", message.readString());

            // Invalid conversion should throw exception and not move the stream
            // position.
            try {
                message.readByte();
                fail("Should have received MessageEOFException");
            } catch (MessageEOFException e) {
            }
        }
        assertNull(consumer.receiveNoWait());
View Full Code Here

            } catch (JMSException ex) {
                return ex.toString();
            }
        } else if (message instanceof StreamMessage) {
            try {
                StreamMessage sm = (StreamMessage) message;
                sm.reset();
                n = sm.readBytes(body);
            } catch (JMSException ex) {
                return ex.toString();
            }
        }
View Full Code Here

    public void testStreamMessage() throws Exception {
        executeTest(new MessageCommand<StreamMessage>() {
            private Long value = new Long(1013);

            public StreamMessage createMessage(Session session) throws JMSException {
                StreamMessage message = session.createStreamMessage();
                message.writeObject(value);
                return message;
            }

            public void completeCheck(StreamMessage message) throws JMSException {
                Assert.assertEquals("The returned stream object was different", value, message.readObject());
            }
        });
    }
View Full Code Here

        ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
        connection.setUseCompression(compressed);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic destination = session.createTopic(destinationName);
        MessageProducer producer = session.createProducer(destination);
        StreamMessage message = session.createStreamMessage();
        message.writeString(builder.toString());
        producer.send(message);
    }
View Full Code Here

        MessageConsumer consumer = session.createConsumer(destination);
        MessageProducer producer = session.createProducer(destination);

        // Send the message.
        {
            StreamMessage message = session.createStreamMessage();
            message.writeString("This is a test to see how it works.");
            producer.send(message);
        }

        // Check the message.
        {
            StreamMessage message = (StreamMessage)consumer.receive(1000);
            assertNotNull(message);

            // Invalid conversion should throw exception and not move the stream
            // position.
            try {
                message.readByte();
                fail("Should have received NumberFormatException");
            } catch (NumberFormatException e) {
            }

            assertEquals("This is a test to see how it works.", message.readString());

            // Invalid conversion should throw exception and not move the stream
            // position.
            try {
                message.readByte();
                fail("Should have received MessageEOFException");
            } catch (MessageEOFException e) {
            }
        }
        assertNull(consumer.receiveNoWait());
View Full Code Here

      QueueReceiver qr = s_rec.createReceiver(q);
      /* Create a sender for sending messages */
      QueueSender qsender = s_send.createSender(q);
      qsender.setDisableMessageTimestamp(false);
      /* create a text message for sending */
      StreamMessage msg = s_send.createStreamMessage();
      /* and write values into it */
      msg.writeByte((byte)0);
      msg.writeBoolean(true);
      msg.writeChar('c');
      msg.writeDouble(1.11d);
      msg.writeFloat(1.1f);
      msg.writeInt(1);
      msg.writeShort((short)1);
      msg.writeString(TEXT);

      /* Send the message */
      qsender.send(msg);
      /* Commit the sending session */
      s_send.commit();
      /* Receive the message */
      msg = (StreamMessage) qr.receiveNoWait();
     
      Assert.assertNotNull("message recieved", msg);
      /* Commit the session to clear the queue */
      s_rec.commit();
      /* Check, that the text of the message is still the same */
     
      Assert.assertEquals("byte", msg.readByte(), (byte) 0);
      Assert.assertEquals("boolean", msg.readBoolean(), true);
      Assert.assertEquals("char", msg.readChar(), 'c');
      Assert.assertEquals("double", msg.readDouble(), 1.11d, 0);
      Assert.assertEquals("float", msg.readFloat(), 1.1f, 0);
      Assert.assertEquals("int", msg.readInt(), 1);
      Assert.assertEquals("short", msg.readShort(), (short) 1);
      Assert.assertEquals("string", msg.readString(), TEXT);
     
    } finally {
      try {
        s_rec.close();
      } catch (Exception ex) {
View Full Code Here

        MessageConsumer consumer = session.createConsumer(destination);
        MessageProducer producer = session.createProducer(destination);

        // Send the message.
        {
            StreamMessage message = session.createStreamMessage();
            message.writeString("This is a test to see how it works.");
            producer.send(message);
        }
       
        // Check the message.
        {
            StreamMessage message = (StreamMessage) consumer.receive(1000);
            assertNotNull(message);
           
            // Invalid conversion should throw exception and not move the stream position.
            try {
                message.readByte();
                fail("Should have received NumberFormatException");
            } catch (NumberFormatException e) {
            }
           
            assertEquals("This is a test to see how it works.", message.readString() );
   
            // Invalid conversion should throw exception and not move the stream position.
            try {
                message.readByte();
                fail("Should have received MessageEOFException");
            } catch (MessageEOFException e) {
            }
        }
        assertNull(consumer.receiveNoWait());
View Full Code Here

                msg.setConnection(connection);
                msg.setObject(objMsg.getObject());
                msg.storeContent();
                activeMessage = msg;
            } else if (message instanceof StreamMessage) {
                StreamMessage streamMessage = (StreamMessage) message;
                streamMessage.reset();
                ActiveMQStreamMessage msg = new ActiveMQStreamMessage();
                msg.setConnection(connection);
                Object obj = null;

                try {
                    while ((obj = streamMessage.readObject()) != null) {
                        msg.writeObject(obj);
                    }
                } catch (MessageEOFException e) {
                    // if an end of message stream as expected
                } catch (JMSException e) {
View Full Code Here

TOP

Related Classes of javax.jms.StreamMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.