List of usage examples for javax.jms Session CLIENT_ACKNOWLEDGE
int CLIENT_ACKNOWLEDGE
To view the source code for javax.jms Session CLIENT_ACKNOWLEDGE.
Click Source Link
From source file:ConsumerTool.java
public void setAckMode(String ackMode) { if ("CLIENT_ACKNOWLEDGE".equals(ackMode)) { this.ackMode = Session.CLIENT_ACKNOWLEDGE; }// ww w . j av a 2 s . c o m if ("AUTO_ACKNOWLEDGE".equals(ackMode)) { this.ackMode = Session.AUTO_ACKNOWLEDGE; } if ("DUPS_OK_ACKNOWLEDGE".equals(ackMode)) { this.ackMode = Session.DUPS_OK_ACKNOWLEDGE; } if ("SESSION_TRANSACTED".equals(ackMode)) { this.ackMode = Session.SESSION_TRANSACTED; } }
From source file:com.adaptris.core.jms.MessageTypeTranslatorCase.java
public void testMoveJmsHeadersAdaptrisMessageToJmsMessage() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); MessageTypeTranslatorImp trans = createTranslator(); try {//www . j a va2 s . c o m broker.start(); Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); addMetadata(msg); addRedundantJmsHeaders(msg); trans.setMoveJmsHeaders(true); start(trans, session); Message jmsMsg = trans.translate(msg); assertEquals(msg.getMetadataValue(JMS_TYPE), jmsMsg.getJMSType()); assertNotSame(msg.getMetadataValue(JMS_CORRELATION_ID), jmsMsg.getJMSCorrelationID()); assertNotSame(msg.getMetadataValue(JMS_TIMESTAMP), jmsMsg.getJMSTimestamp()); assertNotSame(msg.getMetadataValue(JMS_REDELIVERED), jmsMsg.getJMSPriority()); assertNotSame(msg.getMetadataValue(JMS_MESSAGE_ID), jmsMsg.getJMSMessageID()); assertNotSame(msg.getMetadataValue(JMS_EXPIRATION), jmsMsg.getJMSExpiration()); assertNotSame(msg.getMetadataValue(JMS_DELIVERY_MODE), jmsMsg.getJMSDeliveryMode()); assertJmsProperties(jmsMsg); } finally { stop(trans); broker.destroy(); } }
From source file:org.apache.activemq.artemis.tests.integration.persistence.metrics.JournalPendingMessageTest.java
@Test public void testDeliveringStats() throws Exception { AtomicLong publishedMessageSize = new AtomicLong(); Connection connection = cf.createConnection(); connection.start();/* w ww. ja v a 2 s. com*/ Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); MessageProducer producer = session.createProducer(session.createQueue(defaultQueueName)); producer.send(session.createTextMessage("test")); verifyPendingStats(defaultQueueName, 1, publishedMessageSize.get()); verifyPendingDurableStats(defaultQueueName, 1, publishedMessageSize.get()); verifyDeliveringStats(defaultQueueName, 0, 0); MessageConsumer consumer = session.createConsumer(session.createQueue(defaultQueueName)); Message msg = consumer.receive(); verifyDeliveringStats(defaultQueueName, 1, publishedMessageSize.get()); msg.acknowledge(); verifyPendingStats(defaultQueueName, 0, 0); verifyPendingDurableStats(defaultQueueName, 0, 0); verifyDeliveringStats(defaultQueueName, 0, 0); connection.close(); }
From source file:com.chinamobile.bcbsp.comm.ConsumerTool.java
/** * Put message into messageQueue with serialize method. *///from w ww.j a v a2 s .c om public void onMessageOptimistic(Message message) throws IOException { messagesReceived++; try { if (message instanceof BytesMessage) { BytesMessage mapMsg = (BytesMessage) message; BSPMessage bspMsg; int packSize = mapMsg.readInt(); int count = 0; int partitionID; String srcVertexID; String dstVertexID; byte[] tag; byte[] data; int tagLen; int dataLen; while (count < packSize) { partitionID = mapMsg.readInt(); dstVertexID = mapMsg.readUTF(); tagLen = mapMsg.readInt(); tag = new byte[tagLen]; mapMsg.readBytes(tag); dataLen = mapMsg.readInt(); data = new byte[dataLen]; mapMsg.readBytes(data); // bspMsg = new BSPMessage(partitionID, dstVertexID, tag, data); // dst is message if it is not null. bspMsg = new BSPMessage(partitionID, dstVertexID, tag, data); this.messageQueues.incomeAMessage(dstVertexID, bspMsg); this.messageCount++; this.messageBytesCount += bspMsg.size(); count++; } } else { // Message received is not ObjectMessage. LOG.error("[ConsumerTool] Message received is not BytesMessage!"); } if (message.getJMSReplyTo() != null) { replyProducer.send(message.getJMSReplyTo(), session.createTextMessage("Reply: " + message.getJMSMessageID())); } if (transacted) { if ((messagesReceived % batch) == 0) { LOG.info("Commiting transaction for last " + batch + " messages; messages so far = " + messagesReceived); session.commit(); } } else if (ackMode == Session.CLIENT_ACKNOWLEDGE) { if ((messagesReceived % batch) == 0) { LOG.info("Acknowledging last " + batch + " messages; messages so far = " + messagesReceived); message.acknowledge(); } } } catch (JMSException e) { LOG.error("[ConsumerTool] caught: ", e); } finally { if (sleepTime > 0) { try { Thread.sleep(sleepTime); } catch (InterruptedException e) { LOG.error("[ConsumerTool] caught: ", e); } } } }
From source file:com.adaptris.core.jms.MessageTypeTranslatorCase.java
public void testMoveMetadataAdaptrisMessageToJmsMessage() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); MessageTypeTranslatorImp trans = createTranslator(); try {/* w w w .j a v a2s. co m*/ broker.start(); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); addMetadata(msg); Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE); start(trans, session); Message jmsMsg = trans.translate(msg); assertJmsProperties(jmsMsg); } finally { stop(trans); broker.destroy(); } }
From source file:tools.ProducerTool.java
public void parseCommandLine(String[] args) { CommandLineParser parser = new PosixParser(); Options options = new Options(); Option ackModeOpt = OptionBuilder.withLongOpt("acknowledgement-mode").withArgName("ackMode").hasArg() .withDescription(// w w w. ja v a 2 s .c o m "session acknowledgement mode: AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE") .create("a"); options.addOption(ackModeOpt); Option clientIdOpt = OptionBuilder.withLongOpt("client-id").withArgName("id").hasArg() .withDescription("client id string that can optionally be set on a connection").create("c"); options.addOption(clientIdOpt); Option durableOpt = OptionBuilder.withLongOpt("durable").withDescription("create a durable subscriber") .create("d"); options.addOption(durableOpt); Option perMessageSleepOpt = OptionBuilder.withLongOpt("per-message-sleep").withArgName("millis").hasArg() .withDescription("amount of time (in ms) to sleep after receiving each message").create("e"); options.addOption(perMessageSleepOpt); Option connFactOpt = OptionBuilder.withLongOpt("connection-factory-name").withArgName("name").hasArg() .withDescription("name of the connection factory to lookup").create("f"); options.addOption(connFactOpt); Option numThreadsOpt = OptionBuilder.withLongOpt("num-threads").withArgName("num").hasArg() .withDescription("number of threads to run in parallel each with a connection").create("g"); options.addOption(numThreadsOpt); Option helpOpt = OptionBuilder.withLongOpt("help").withDescription("show help").create("h"); options.addOption(helpOpt); Option jndiDestOpt = OptionBuilder.withLongOpt("jndi-lookup-destination") .withDescription("lookup destinations with jndi").create("j"); options.addOption(jndiDestOpt); Option bytesLengthOpt = OptionBuilder.withLongOpt("bytes-message-length").withArgName("length").hasArg() .withDescription("use a bytes message of a specific length").create("l"); options.addOption(bytesLengthOpt); Option numMessagesOpt = OptionBuilder.withLongOpt("num-messages").withArgName("num").hasArg() .withDescription("number of messages to receive before stopping").create("m"); options.addOption(numMessagesOpt); Option destNameOpt = OptionBuilder.withLongOpt("destination-name").withArgName("name").hasArg() .withDescription("name of the destination to receive from").create("n"); options.addOption(destNameOpt); Option controlOpt = OptionBuilder.withLongOpt("final-control-message") .withDescription("use a control message as the final message").create("o"); options.addOption(controlOpt); Option tempOpt = OptionBuilder.withLongOpt("temporary-destination") .withDescription("use a temporary destination").create("p"); options.addOption(tempOpt); Option useQueueOpt = OptionBuilder.withLongOpt("queue-destination") .withDescription("use a queue destination").create("q"); options.addOption(useQueueOpt); Option transOpt = OptionBuilder.withLongOpt("transacted").withDescription("use a transacted session") .create("t"); options.addOption(transOpt); Option groupIdOpt = OptionBuilder.withLongOpt("message-group-id").withArgName("groupId").hasArg() .withDescription("JMSXGroupID").create("x"); options.addOption(groupIdOpt); Option batchSizeOpt = OptionBuilder.withLongOpt("batch-size").withArgName("size").hasArg() .withDescription( "size of the batch to ack or commit when using client ack mode or transacted sessions") .create("z"); options.addOption(batchSizeOpt); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("h")) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ProducerTool", options, true); System.exit(0); } if (line.hasOption("a")) { String ackModeStr = line.getOptionValue("a"); if (ackModeStr.equalsIgnoreCase("AUTO_ACKNOWLEDGE")) { acknowledgeMode = Session.AUTO_ACKNOWLEDGE; } else if (ackModeStr.equalsIgnoreCase("CLIENT_ACKNOWLEDGE")) { acknowledgeMode = Session.CLIENT_ACKNOWLEDGE; } else if (ackModeStr.equalsIgnoreCase("DUPS_OK_ACKNOWLEDGE")) { acknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE; } else if (ackModeStr.equalsIgnoreCase("SESSION_TRANSACTED")) { acknowledgeMode = Session.SESSION_TRANSACTED; } else { throw new ParseException("Invalid value for acknowledge mode: " + ackModeStr); } } if (line.hasOption("c")) { clientId = line.getOptionValue("c"); } if (line.hasOption("d")) { durable = true; } if (line.hasOption("e")) { perMessageSleepMS = Integer.parseInt(line.getOptionValue("e")); } if (line.hasOption("f")) { connectionFactoryName = line.getOptionValue("f"); } if (line.hasOption("g")) { numThreads = Integer.parseInt(line.getOptionValue("g")); } if (line.hasOption("j")) { jndiLookupDestinations = true; } if (line.hasOption("l")) { bytesLength = Integer.parseInt(line.getOptionValue("l")); } if (line.hasOption("m")) { numMessages = Integer.parseInt(line.getOptionValue("m")); } if (line.hasOption("n")) { destinationName = line.getOptionValue("n"); } if (line.hasOption("o")) { useFinalControlMessage = true; } if (line.hasOption("p")) { useTemporaryDestinations = true; } if (line.hasOption("q")) { useQueueDestinations = true; } if (line.hasOption("t")) { transacted = true; } if (line.hasOption("x")) { messageGroupId = line.getOptionValue("x"); } if (line.hasOption("z")) { batchSize = Integer.parseInt(line.getOptionValue("z")); } } catch (ParseException exp) { LOGGER.error("Commandline parsing exception: " + exp.getMessage(), exp); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("ProducerTool", options, true); System.exit(-1); } }
From source file:com.adaptris.core.jms.MessageTypeTranslatorCase.java
public void testMoveMetadata_AdaptrisMessageToJmsMessage_RemoveAll() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); MessageTypeTranslatorImp trans = createTranslator(); trans.setMetadataFilter(new RemoveAllMetadataFilter()); try {/*from ww w . j a va 2 s. c om*/ broker.start(); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); addMetadata(msg); Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE); start(trans, session); Message jmsMsg = trans.translate(msg); assertNull(jmsMsg.getStringProperty(STRING_METADATA)); assertNull(jmsMsg.getStringProperty(BOOLEAN_METADATA)); assertNull(jmsMsg.getStringProperty(INTEGER_METADATA)); } finally { stop(trans); broker.destroy(); } }
From source file:edu.psu.citeseerx.messaging.MsgService.java
/** * Utility for translating String representations of acknowledgement * modes into their int encoding. Default is CLIENT_ACKNOWLEDGE, so * any string that is not understood will result in a CLIENT_ACKNOWLEDGE * mode./*from w ww . j av a 2 s. c om*/ * @param modeStr * @return int representation of string acknowledgement */ protected int getAckMode(String modeStr) { int mode = Session.CLIENT_ACKNOWLEDGE; if (modeStr.equalsIgnoreCase("AUTO_ACKNOWLEDGE")) { mode = Session.AUTO_ACKNOWLEDGE; } if (modeStr.equalsIgnoreCase("DUPS_OK_ACKNOWLEDGE")) { mode = Session.DUPS_OK_ACKNOWLEDGE; } return mode; }
From source file:nl.nn.adapterframework.jms.JmsListenerBase.java
protected String retrieveIdFromMessage(Message message, Map threadContext) throws ListenerException { String cid = "unset"; String mode = "unknown"; String id = "unset"; Date tsSent = null;//from w ww .ja v a 2 s . c o m Destination replyTo = null; try { mode = deliveryModeToString(message.getJMSDeliveryMode()); } catch (JMSException ignore) { log.debug("ignoring JMSException in getJMSDeliveryMode()", ignore); } // -------------------------- // retrieve MessageID // -------------------------- try { id = message.getJMSMessageID(); } catch (JMSException ignore) { log.debug("ignoring JMSException in getJMSMessageID()", ignore); } // -------------------------- // retrieve CorrelationID // -------------------------- try { if (isForceMessageIdAsCorrelationId()) { if (log.isDebugEnabled()) log.debug("forcing the messageID to be the correlationID"); cid = id; } else { cid = message.getJMSCorrelationID(); if (cid == null) { cid = id; log.debug("Setting correlation ID to MessageId"); } } } catch (JMSException ignore) { log.debug("ignoring JMSException in getJMSCorrelationID()", ignore); } // -------------------------- // retrieve TimeStamp // -------------------------- try { long lTimeStamp = message.getJMSTimestamp(); tsSent = new Date(lTimeStamp); } catch (JMSException ignore) { log.debug("ignoring JMSException in getJMSTimestamp()", ignore); } // -------------------------- // retrieve ReplyTo address // -------------------------- try { replyTo = message.getJMSReplyTo(); } catch (JMSException ignore) { log.debug("ignoring JMSException in getJMSReplyTo()", ignore); } if (log.isDebugEnabled()) { log.debug(getLogPrefix() + "listener on [" + getDestinationName() + "] got message with JMSDeliveryMode=[" + mode + "] \n JMSMessageID=[" + id + "] \n JMSCorrelationID=[" + cid + "] \n Timestamp Sent=[" + DateUtils.format(tsSent) + "] \n ReplyTo=[" + ((replyTo == null) ? "none" : replyTo.toString()) + "] \n Message=[" + message.toString() + "]"); } PipeLineSessionBase.setListenerParameters(threadContext, id, cid, null, tsSent); threadContext.put("timestamp", tsSent); threadContext.put("replyTo", replyTo); try { if (getAckMode() == Session.CLIENT_ACKNOWLEDGE) { message.acknowledge(); log.debug("Listener on [" + getDestinationName() + "] acknowledged message"); } } catch (JMSException e) { log.error("Warning in ack", e); } return cid; }
From source file:com.adaptris.core.jms.MessageTypeTranslatorCase.java
public void testMoveMetadata_AdaptrisMessageToJmsMessage_WithFilter() throws Exception { EmbeddedActiveMq broker = new EmbeddedActiveMq(); MessageTypeTranslatorImp trans = createTranslator(); RegexMetadataFilter regexp = new RegexMetadataFilter(); regexp.addExcludePattern("IntegerMetadataKey"); trans.setMetadataFilter(regexp);/*w w w . j a v a 2s.co m*/ try { broker.start(); AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(); addMetadata(msg); Session session = broker.createConnection().createSession(false, Session.CLIENT_ACKNOWLEDGE); start(trans, session); Message jmsMsg = trans.translate(msg); assertEquals(STRING_VALUE, jmsMsg.getStringProperty(STRING_METADATA)); assertEquals(BOOLEAN_VALUE, jmsMsg.getStringProperty(BOOLEAN_METADATA)); assertEquals(Boolean.valueOf(BOOLEAN_VALUE).booleanValue(), jmsMsg.getBooleanProperty(BOOLEAN_METADATA)); assertNull(jmsMsg.getStringProperty(INTEGER_METADATA)); } finally { stop(trans); broker.destroy(); } }