Package org.apache.activemq.command

Examples of org.apache.activemq.command.ActiveMQTextMessage


     * @return an ActiveMQTextMessage
     * @throws JMSException if the JMS provider fails to create this message due
     *                 to some internal error.
     */
    public TextMessage createTextMessage(String text) throws JMSException {
        ActiveMQTextMessage message = new ActiveMQTextMessage();
        message.setText(text);
        configureMessage(message);
        return message;
    }
View Full Code Here


        message.setStringProperty(LENGTH10STRING, LENGTH10STRING);
        producer.send(message);

        messageList.assertMessagesArrived(1);

        ActiveMQTextMessage received = ((ActiveMQTextMessage) messageList
                .flushMessages().get(0));

        assertEquals(LENGTH10STRING, received.getText());
        assertTrue(received.getProperties().size() > 0);
        assertTrue(received.propertyExists(LENGTH10STRING));
        assertEquals(LENGTH10STRING, received.getStringProperty(LENGTH10STRING));

        /**
         * As specified by getSize(), the size (memory usage) of the body should
         * be length of text * 2. Unsure of how memory usage is calculated for
         * properties, but should probably not be less than the sum of (string)
         * lengths for the key name and value.
         */

        final int sizeShouldBeNoLessThan = LENGTH10STRING.length() * 4 + received.DEFAULT_MINIMUM_MESSAGE_SIZE;
        assertTrue("Message size was smaller than expected: " + received.getSize(),
                received.getSize() >= sizeShouldBeNoLessThan);
        assertFalse(LENGTH10STRING.length() * 2 == received.getSize());
    }
View Full Code Here

    protected int browseMessages(QueueBrowser browser, String name) throws Exception {
        Enumeration msgs = browser.getEnumeration();
        int browsedMessage = 0;
        while (msgs.hasMoreElements()) {
            browsedMessage++;
            ActiveMQTextMessage message = (ActiveMQTextMessage)msgs.nextElement();
            LOG.info(name + " browsed: " + message.getText() + " " + message.getDestination() " " + message.getMessageId() + " " + Arrays.toString(message.getBrokerPath()));
        }
        return browsedMessage;
    }
View Full Code Here

                    if (consume) {
                        if (count != 0) {
                            MessageConsumer consumer = createSyncConsumer(broker, dest);
                            totalCount += count;
                            for (int i = 0; i < count; i++) {
                                ActiveMQTextMessage message = (ActiveMQTextMessage)consumer.receive(1000);
                                LOG.info(broker + " consumer: " + message.getText() + " " + message.getDestination() " " + message.getMessageId() + " " + Arrays.toString(message.getBrokerPath()));
                                if (message == null) break;
                            }
                        }
                    } else {
                        totalCount = count;
View Full Code Here

    protected ActiveMQDestination createActiveMQDestination(String string) {
        return new ActiveMQQueue(string);
    }

    protected Message createMessage(String string) throws Exception {
        ActiveMQTextMessage message = (ActiveMQTextMessage)ActiveMQTextMessageTest.SINGLETON.createObject();
        message.setText(string);
        return message;
    }
View Full Code Here

        assertEquals("getJMSPriority", 3, message.getJMSPriority());
        assertEquals("foo", "abc", message.getStringProperty("foo"));
        assertEquals("bar", "123", message.getStringProperty("bar"));

        assertEquals("JMSXGroupID", "abc", message.getStringProperty("JMSXGroupID"));
        ActiveMQTextMessage amqMessage = (ActiveMQTextMessage)message;
        assertEquals("GroupID", "abc", amqMessage.getGroupID());
    }
View Full Code Here

        message.setPersistent(deliveryMode == DeliveryMode.PERSISTENT);
        return message;
    }
   
    protected Message createMessage(ProducerInfo producerInfo, ActiveMQDestination destination) {
        ActiveMQTextMessage message = new ActiveMQTextMessage();
        message.setMessageId(new MessageId(producerInfo, ++msgIdGenerator));
        message.setDestination(destination);
        message.setPersistent(false);
        try {
            message.setText("Test Message Payload.");
        } catch (MessageNotWriteableException e) {
        }
        return message;
    }
View Full Code Here

               String point = "activemq:"
                 + ((ActiveMQDestination)destination).getPhysicalName().replace("//", "")
                 + "?requestTimeout=" + requestTimeout;
               try {
                 String body = (String)client.getProducerTemplate().requestBody(point, text);
                   ActiveMQTextMessage answer = new ActiveMQTextMessage();
                   answer.setText(body);
                 writeMessageResponse(response.getWriter(), answer);
               } catch (Exception e) {
                 IOException ex = new IOException();
                 ex.initCause(e);
                 throw ex;
View Full Code Here

            addItem(CompositeDataConstants.MESSAGE_TEXT, CompositeDataConstants.MESSAGE_TEXT, SimpleType.STRING);
        }

        @Override
        public Map<String, Object> getFields(Object o) throws OpenDataException {
            ActiveMQTextMessage m = (ActiveMQTextMessage)o;
            Map<String, Object> rc = super.getFields(o);
            try {
                rc.put(CompositeDataConstants.MESSAGE_TEXT, "" + m.getText());
            } catch (JMSException e) {
                rc.put(CompositeDataConstants.MESSAGE_TEXT, "");
            }
            return rc;
        }
View Full Code Here

        try {

            connection = cf.createConnection(userName, password);
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer producer = session.createProducer(dest);
            ActiveMQTextMessage msg = (ActiveMQTextMessage) session.createTextMessage(body);

            for (Iterator iter = headers.entrySet().iterator(); iter.hasNext();) {
                Map.Entry entry = (Map.Entry) iter.next();
                msg.setObjectProperty((String) entry.getKey(), entry.getValue());
            }

            producer.setDeliveryMode(msg.getJMSDeliveryMode());
            producer.setPriority(msg.getPriority());
            long ttl = msg.getExpiration() - System.currentTimeMillis();
            producer.setTimeToLive(ttl > 0 ? ttl : 0);
            producer.send(msg);

            return msg.getJMSMessageID();

        } finally {
            connection.close();
        }
View Full Code Here

TOP

Related Classes of org.apache.activemq.command.ActiveMQTextMessage

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.