Example usage for javax.jms TextMessage setLongProperty

List of usage examples for javax.jms TextMessage setLongProperty

Introduction

In this page you can find the example usage for javax.jms TextMessage setLongProperty.

Prototype


void setLongProperty(String name, long value) throws JMSException;

Source Link

Document

Sets a long property value with the specified name into the message.

Usage

From source file:com.mothsoft.alexis.engine.retrieval.DocumentRetrievalTaskImpl.java

private String requestParse(final Long documentId, final String content) {
    Connection connection = null;
    Session session = null;/*w ww.j  a  v  a 2 s  . co  m*/
    MessageProducer producer = null;

    // set up JMS connection, session, consumer, producer
    try {
        connection = this.connectionFactory.createConnection();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        producer = session.createProducer(this.requestQueue);

        logger.info("Sending parse request, document ID: " + documentId);
        final TextMessage textMessage = session.createTextMessage(content);
        textMessage.setJMSReplyTo(this.responseQueue);
        textMessage.setLongProperty(DOCUMENT_ID, documentId);

        producer.send(textMessage);
    } catch (JMSException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            if (producer != null) {
                producer.close();
            }
            if (session != null) {
                session.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (JMSException e) {
            throw new RuntimeException(e);
        }
    }

    return content;
}

From source file:org.hawkular.apm.server.jms.AbstractPublisherJMS.java

/**
 * This method publishes the supplied items.
 *
 * @param tenantId The tenant id/*from  www  .  j a v  a2 s  . c o  m*/
 * @param items The items
 * @param subscriber The optional subscriber name
 * @param retryCount The retry count
 * @param delay The delay
 * @throws Exception Failed to publish
 */
protected void doPublish(String tenantId, List<T> items, String subscriber, int retryCount, long delay)
        throws Exception {
    String data = mapper.writeValueAsString(items);

    TextMessage tm = session.createTextMessage(data);

    if (tenantId != null) {
        tm.setStringProperty("tenant", tenantId);
    }

    if (subscriber != null) {
        tm.setStringProperty("subscriber", subscriber);
    }

    tm.setIntProperty("retryCount", retryCount);

    if (delay > 0) {
        tm.setLongProperty("_AMQ_SCHED_DELIVERY", System.currentTimeMillis() + delay);
    }

    if (log.isLoggable(Level.FINEST)) {
        log.finest("Publish: " + tm);
    }

    producer.send(tm);
}

From source file:com.bleum.canton.jms.scheduler.AbstractJMSScheduler.java

/**
 * Send JMS message. Can be override.//w  ww  .  j av a 2s .c  om
 * 
 * @param task
 */
protected void sendMessage(final JMSTask task) {
    if (jmsSender == null) {
        throw new RuntimeException("jmsSender is null.");
    }
    MessageCreator mc = new MessageCreator() {

        public Message createMessage(Session session) throws JMSException {
            TextMessage om = session.createTextMessage();
            om.setText(formMessage(task));
            om.setIntProperty("clientAck", clientAck);
            if (clientAck == JMSTaskConstant.CLIENT_ACKNOWLEDGE) {
                om.setLongProperty("taskId", task.getId());
                om.setJMSReplyTo(replyQueue);
            }
            return om;
        }
    };
    jmsSender.send(mc);
}

From source file:org.apache.activemq.leveldb.test.ReplicatedLevelDBBrokerTest.java

@Test
@Ignore/* w  ww . ja  va  2s  . c  o  m*/
public void testReplicationQuorumLoss() throws Throwable {

    System.out.println("======================================");
    System.out.println(" Start 2 ActiveMQ nodes.");
    System.out.println("======================================");
    startBrokerAsync(createBrokerNode("node-1", port));
    startBrokerAsync(createBrokerNode("node-2", port));
    BrokerService master = waitForNextMaster();
    System.out.println("======================================");
    System.out.println(" Start the producer and consumer");
    System.out.println("======================================");

    final AtomicBoolean stopClients = new AtomicBoolean(false);
    final ArrayBlockingQueue<String> errors = new ArrayBlockingQueue<String>(100);
    final AtomicLong receivedCounter = new AtomicLong();
    final AtomicLong sentCounter = new AtomicLong();
    Thread producer = startFailoverClient("producer", new Client() {
        @Override
        public void execute(Connection connection) throws Exception {
            Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
            MessageProducer producer = session.createProducer(session.createQueue("test"));
            long actual = 0;
            while (!stopClients.get()) {
                TextMessage msg = session.createTextMessage("Hello World");
                msg.setLongProperty("id", actual++);
                producer.send(msg);
                sentCounter.incrementAndGet();
            }
        }
    });

    Thread consumer = startFailoverClient("consumer", new Client() {
        @Override
        public void execute(Connection connection) throws Exception {
            connection.start();
            Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
            MessageConsumer consumer = session.createConsumer(session.createQueue("test"));
            long expected = 0;
            while (!stopClients.get()) {
                Message msg = consumer.receive(200);
                if (msg != null) {
                    long actual = msg.getLongProperty("id");
                    if (actual != expected) {
                        errors.offer("Received got unexpected msg id: " + actual + ", expected: " + expected);
                    }
                    msg.acknowledge();
                    expected = actual + 1;
                    receivedCounter.incrementAndGet();
                }
            }
        }
    });

    try {
        assertCounterMakesProgress(sentCounter, 10, TimeUnit.SECONDS);
        assertCounterMakesProgress(receivedCounter, 5, TimeUnit.SECONDS);
        assertNull(errors.poll());

        System.out.println("======================================");
        System.out.println(" Master should stop once the quorum is lost.");
        System.out.println("======================================");
        ArrayList<BrokerService> stopped = stopSlaves();// stopping the slaves should kill the quorum.
        assertStopsWithin(master, 10, TimeUnit.SECONDS);
        assertNull(errors.poll()); // clients should not see an error since they are failover clients.
        stopped.add(master);

        System.out.println("======================================");
        System.out.println(" Restart the slave. Clients should make progress again..");
        System.out.println("======================================");
        startBrokersAsync(createBrokerNodes(stopped));
        assertCounterMakesProgress(sentCounter, 10, TimeUnit.SECONDS);
        assertCounterMakesProgress(receivedCounter, 5, TimeUnit.SECONDS);
        assertNull(errors.poll());
    } catch (Throwable e) {
        e.printStackTrace();
        throw e;
    } finally {
        // Wait for the clients to stop..
        stopClients.set(true);
        producer.join();
        consumer.join();
    }
}

From source file:org.codehaus.stomp.StompTest.java

public void testSubscribeWithMessageSentWithProperties() throws Exception {

    String frame = "CONNECT\n" + "login: brianm\n" + "passcode: wombats\n\n" + Stomp.NULL;
    sendFrame(frame);//from ww w  .  ja v a  2  s .  c  o  m

    frame = receiveFrame(100000);
    Assert.assertTrue(frame.startsWith("CONNECTED"));

    frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "ack:auto\n\n" + Stomp.NULL;
    sendFrame(frame);

    MessageProducer producer = session.createProducer(queue);
    TextMessage message = session.createTextMessage("Hello World");
    message.setStringProperty("s", "value");
    message.setBooleanProperty("n", false);
    message.setByteProperty("byte", (byte) 9);
    message.setDoubleProperty("d", 2.0);
    message.setFloatProperty("f", (float) 6.0);
    message.setIntProperty("i", 10);
    message.setLongProperty("l", 121);
    message.setShortProperty("s", (short) 12);
    producer.send(message);

    frame = receiveFrame(10000);
    Assert.assertTrue(frame.startsWith("MESSAGE"));

    //        System.out.println("out: "+frame);

    frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
    sendFrame(frame);
}

From source file:org.openanzo.combus.endpoint.BaseServiceListener.java

private TextMessage sendJMSErrorMessage(Destination replyTo, Message request, Throwable jmex, long errorCode,
        String... args) throws JMSException {
    try {//from   ww w .j ava2 s.  c  om
        if (replyTo != null) {
            if (log.isWarnEnabled()) {
                log.warn(LogUtils.COMBUS_MARKER,
                        "Exception while ServiceListener [" + name + "] was precessing request.", jmex);

            }
            String message = null;
            if (jmex instanceof AnzoException) {
                message = ((AnzoException) jmex).getMessage(false);
            } else if (jmex instanceof AnzoRuntimeException) {
                message = ((AnzoRuntimeException) jmex).getMessage(false);
            } else {
                message = jmex.getMessage();
            }
            TextMessage response = session.createTextMessage(message);
            response.setJMSCorrelationID(request.getJMSCorrelationID());
            response.setBooleanProperty(SerializationConstants.operationFailed, true);
            response.setLongProperty(SerializationConstants.errorTags, 0);
            response.setLongProperty(SerializationConstants.errorCode, errorCode);
            response.setIntProperty(SerializationConstants.protocolVersion, Constants.VERSION);
            // send a single arg string for compat. with older readers
            response.setStringProperty(SerializationConstants.errorMessageArg, Arrays.toString(args));

            // send the individual error args for readers that can make use of them
            for (int i = 0; i < args.length; i++) {
                response.setStringProperty(SerializationConstants.errorMessageArg + i, args[i]);
            }

            // we log all JMS messages, even errors.
            if (log.isDebugEnabled()) {
                log.debug(LogUtils.COMBUS_MARKER,
                        MessageUtils.prettyPrint(response, "Sending Response to " + replyTo));
            }
            mp.send(replyTo, response);
            return response;
        }
    } catch (JMSException jmsex) {
        log.debug(LogUtils.COMBUS_MARKER, "Error sending error message to client", jmsex);
    }
    return null;
}

From source file:org.wso2.carbon.appfactory.eventing.jms.AFMessageListener.java

@Override
public void onMessage(Message message) {
    if (log.isDebugEnabled()) {
        if (message instanceof MapMessage) {
            try {
                String messageBody = ((MapMessage) message).getString(TopicPublisher.MESSAGE_BODY);
                log.debug("Received a message:" + messageBody);
            } catch (JMSException e) {
                log.error("Error while getting message content.", e);
            }//  www . ja v  a  2s.  c o  m
        }
    }
    MapMessage mapMessage;
    if (message instanceof MapMessage) {
        mapMessage = (MapMessage) message;
        MessageStore.getInstance().addMessage(this.subscriptionId, mapMessage);
    } else if (message instanceof TextMessage) {
        //Todo:remove this. we only support mapMessages initially and below code is only for testing purpose.
        final TextMessage textMessage = (TextMessage) message;
        mapMessage = new MapMessage() {
            @Override
            public boolean getBoolean(String s) throws JMSException {
                return false; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public byte getByte(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public short getShort(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public char getChar(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public int getInt(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public long getLong(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public float getFloat(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public double getDouble(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getString(String s) throws JMSException {
                return textMessage.getText();
            }

            @Override
            public byte[] getBytes(String s) throws JMSException {
                return new byte[0]; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Object getObject(String s) throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Enumeration getMapNames() throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setBoolean(String s, boolean b) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setByte(String s, byte b) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setShort(String s, short i) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setChar(String s, char c) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setInt(String s, int i) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setLong(String s, long l) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setFloat(String s, float v) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setDouble(String s, double v) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setString(String s, String s2) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setBytes(String s, byte[] bytes) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setBytes(String s, byte[] bytes, int i, int i2) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setObject(String s, Object o) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public boolean itemExists(String s) throws JMSException {
                return false; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getJMSMessageID() throws JMSException {
                return textMessage.getJMSMessageID();
            }

            @Override
            public void setJMSMessageID(String s) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public long getJMSTimestamp() throws JMSException {
                return textMessage.getJMSTimestamp();
            }

            @Override
            public void setJMSTimestamp(long l) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public byte[] getJMSCorrelationIDAsBytes() throws JMSException {
                return new byte[0]; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setJMSCorrelationIDAsBytes(byte[] bytes) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setJMSCorrelationID(String s) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getJMSCorrelationID() throws JMSException {
                return textMessage.getJMSCorrelationID();
            }

            @Override
            public Destination getJMSReplyTo() throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setJMSReplyTo(Destination destination) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Destination getJMSDestination() throws JMSException {
                return textMessage.getJMSDestination();
            }

            @Override
            public void setJMSDestination(Destination destination) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public int getJMSDeliveryMode() throws JMSException {
                return textMessage.getJMSDeliveryMode();
            }

            @Override
            public void setJMSDeliveryMode(int i) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public boolean getJMSRedelivered() throws JMSException {
                return textMessage.getJMSRedelivered();
            }

            @Override
            public void setJMSRedelivered(boolean b) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getJMSType() throws JMSException {
                return textMessage.getJMSType();
            }

            @Override
            public void setJMSType(String s) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public long getJMSExpiration() throws JMSException {
                return textMessage.getJMSExpiration();
            }

            @Override
            public void setJMSExpiration(long l) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public int getJMSPriority() throws JMSException {
                return textMessage.getJMSPriority();
            }

            @Override
            public void setJMSPriority(int i) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void clearProperties() throws JMSException {
                textMessage.clearProperties();
            }

            @Override
            public boolean propertyExists(String s) throws JMSException {
                return textMessage.propertyExists(s);
            }

            @Override
            public boolean getBooleanProperty(String s) throws JMSException {
                return false; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public byte getByteProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public short getShortProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public int getIntProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public long getLongProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public float getFloatProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public double getDoubleProperty(String s) throws JMSException {
                return 0; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getStringProperty(String s) throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Object getObjectProperty(String s) throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public Enumeration getPropertyNames() throws JMSException {
                return null; //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setBooleanProperty(String s, boolean b) throws JMSException {
                //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public void setByteProperty(String s, byte b) throws JMSException {
                textMessage.setByteProperty(s, b);
            }

            @Override
            public void setShortProperty(String s, short i) throws JMSException {
                textMessage.setShortProperty(s, i);
            }

            @Override
            public void setIntProperty(String s, int i) throws JMSException {
                textMessage.setIntProperty(s, i);
            }

            @Override
            public void setLongProperty(String s, long l) throws JMSException {
                textMessage.setLongProperty(s, l);
            }

            @Override
            public void setFloatProperty(String s, float v) throws JMSException {
                textMessage.setFloatProperty(s, v);
            }

            @Override
            public void setDoubleProperty(String s, double v) throws JMSException {
                textMessage.setDoubleProperty(s, v);
            }

            @Override
            public void setStringProperty(String s, String s2) throws JMSException {
                textMessage.setStringProperty(s, s2);
            }

            @Override
            public void setObjectProperty(String s, Object o) throws JMSException {
                textMessage.setObjectProperty(s, o);
            }

            @Override
            public void acknowledge() throws JMSException {
                textMessage.acknowledge();
            }

            @Override
            public void clearBody() throws JMSException {
                textMessage.clearBody();
            }
        };
        MessageStore.getInstance().addMessage(this.subscriptionId, mapMessage);
    }

}