Package javax.jms

Examples of javax.jms.BytesMessage


        if(isQueue)
            dest = session.createQueue(name);
        else
            dest = session.createTopic(name);
        MessageProducer producer = session.createProducer(dest);
        BytesMessage msg = session.createBytesMessage();
        msg.writeBytes(content);
        producer.send(msg);
        producer.close();
    }
View Full Code Here


        if(isQueue)
            dest = session.createQueue(name);
        else
            dest = session.createTopic(name);
        MessageProducer producer = session.createProducer(dest);
        BytesMessage msg = session.createBytesMessage();
        msg.writeBytes(content);
        for(Entry<String, String> ent : props.entrySet())
            msg.setStringProperty(ent.getKey(), ent.getValue());
        msg.setStringProperty(ProducerSession.MIST_MESSAGE_TTL, new Long(ttl).toString());
        producer.setTimeToLive(ttl);
        producer.send(msg);
        producer.close();
    }
View Full Code Here

            } else {
                headers.put(StompFrameMessage.CommonHeader.CONTENTLENGTH,
                            String.valueOf(0));
            }
        } else if (jmsmsg instanceof BytesMessage) {
            BytesMessage m = (BytesMessage)jmsmsg;
            byte[] data = new byte[(int)m.getBodyLength()];
            m.readBytes(data);
            message.setBody(data);
            headers.put(StompFrameMessage.CommonHeader.CONTENTLENGTH,
                        String.valueOf(data.length));

        } else {
View Full Code Here

    protected Message createMessage(final Object event) throws JMSException
    {
        final String eventStr = event.toString();
        if (useBytesMessage.get()) {
            final BytesMessage msg = session.createBytesMessage();
            msg.writeBytes(eventStr.getBytes(UTF8));
            return msg;
        }
        return session.createTextMessage(eventStr);
    }
View Full Code Here

        }
    }

    public synchronized void sendMessageBytes(byte[] data, HashMap<String, String> props) throws MistException {
        try {
            BytesMessage message = getJMSSession().createBytesMessage();
            message.setBooleanProperty("JMS_SUN_COMPRESS", true);
            for(Map.Entry<String, String> ent: props.entrySet()) {
                try {
                    message.setStringProperty(ent.getKey(), ent.getValue());
                }
                catch(JMSException e) {
                    logger.warn(String.format("property (%s, %s) can not be set, skip", ent.getKey(), ent.getValue()));
                }
            }
            message.writeBytes(data);
            getProducer().send(message);
        }
        catch(JMSException e) {
            logger.error(e.getMessage(), e);
            throw new MistException(String.format("producer (%d): %s", getSessionId(), e.getMessage()));
View Full Code Here

        }
    }

    public synchronized void sendMessageBytes(byte[] data) throws MistException {
        try {
            BytesMessage message = getJMSSession().createBytesMessage();
            message.writeBytes(data);
            getProducer().send(message);
        }
        catch(JMSException e) {
            logger.error(e.getMessage(), e);
            throw new MistException(String.format("producer (%d): %s", getSessionId(), e.getMessage()));
View Full Code Here

        assertNotNull(producer);

        /**
         * Deliver a message
         */
        BytesMessage msg = c.getJMSSession().createBytesMessage();
        msg.writeBytes("test".getBytes());
        producer.send(msg);
        assertEquals("test", new String(brk.getMessage(true, "foo.out")));

        /**
         * Test add another queue client
         */
        clientConfig = genClientConfig("bar.out", true, true);
        c = sess.addClient(clientConfig);
        assertEquals(clientConfig, sess.findClient(new Exchange("queue:bar.out")).getConfig());
        sess.open(false);
        producer = sess.findClient(new Exchange("queue:bar.out")).getProducer();
        assertNotNull(producer);

        msg = c.getJMSSession().createBytesMessage();
        msg.writeBytes("test_bar".getBytes());
        producer.send(msg);
        assertEquals("test_bar", new String(brk.getMessage(true, "bar.out")));

        brk.stop();
    }
View Full Code Here

        /**
         * Get a message and ack
         */
        brk.sendMessage(true, "foo.in", "foo".getBytes());
        BytesMessage msgin = brk.getBytesMessage(true, "foo.in");
        new OnMessageRunner(sess, msgin).start();
        packet.read(socketInput);
        MistMessage.MessageBlock mBlock = MistMessage.MessageBlock.newBuilder().mergeFrom(packet.getPayload()).build();
        assertEquals("queue:foo.in", mBlock.getId());
        assertEquals("foo", new String(mBlock.getMessage().toByteArray()));
View Full Code Here

            catch (IOException ex) {
                log.warn("Got an error from the message queue", ex);
            }
        }
        else if (message instanceof BytesMessage) {
            final BytesMessage byteMessage = (BytesMessage) message;
            long llen;
            try {
                llen = byteMessage.getBodyLength();
            }
            catch (JMSException e) {
                log.warn("Unable to get message length", e);
                return;
            }

            if (llen > Integer.MAX_VALUE) { // should never occur but...
                log.error("Ridiculously huge message payload, above 32-bit length");
            }
            else {
                final int len = (int) llen;
                final byte[] data = new byte[len];
                final int readLen;
                try {
                    readLen = byteMessage.readBytes(data);
                }
                catch (JMSException e) {
                    log.warn("Unable to get message bytes", e);
                    return;
                }
View Full Code Here

   }


   public void testCopyOnForeignBytesMessage() throws JMSException
   {
      BytesMessage foreignBytesMessage = new SimpleJMSBytesMessage();
      for(int i = 0; i < 20; i++)
      {
         foreignBytesMessage.writeByte((byte)i);
      }

      JBossBytesMessage copy = new JBossBytesMessage(foreignBytesMessage, 0);

      foreignBytesMessage.reset();
      copy.reset();

      ensureEquivalent(foreignBytesMessage, copy);
   }
View Full Code Here

TOP

Related Classes of javax.jms.BytesMessage

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.