@Override public void onMessage(Message msg) { try { LOG.trace("Queuing msg [" + msg.getJMSMessageID() + "]"); } catch (JMSException e) { // Nothing here, could not get message id } this.queue.offer(msg); }
/** * Fail a batch with the given transaction id. This is called when a batch is timed out, or a new batch with a * matching transaction id is emitted. Note that the current implementation does nothing - i.e. it discards * messages that have been failed. * @param transactionId The transaction id of the failed batch * @param messages The list of messages to fail. */ private void fail(Long transactionId, List<Message> messages) { LOG.debug("Failure for batch with transaction id " + transactionId + " for " + name); if (messages != null) { for (Message msg : messages) { try { LOG.trace("Failed message " + msg.getJMSMessageID()); } catch (JMSException e) { LOG.warn("Could not identify failed message ", e); } } } else { LOG.warn("Failed batch has no messages with transaction id " + transactionId); } }
/** * Checks if this message has been seen before * * @param message * @return true if the message is a duplicate * @throws JMSException */ public boolean isDuplicate(Message message) throws JMSException { return isDuplicate(message.getJMSMessageID()); }
/** * Check the message is in order * * @param msg * * @return true if the id is in order * * @throws JMSException */ public boolean isInOrder(Message msg) throws JMSException { return isInOrder(msg.getJMSMessageID()); }
/** * Post-process the given response message before it will be sent. * <p>The default implementation sets the response's correlation id * to the request message's correlation id, if any; otherwise to the * request message id. * @param request the original incoming JMS message * @param response the outgoing JMS message about to be sent * @throws JMSException if thrown by JMS API methods * @see javax.jms.Message#setJMSCorrelationID */ protected void postProcessResponse(Message request, Message response) throws JMSException { String correlation = request.getJMSCorrelationID(); if (correlation == null) { correlation = request.getJMSMessageID(); } response.setJMSCorrelationID(correlation); }
@Override void emit(final Message msg) { LOG.debug("Received msg {}, Requesting acks.", msg); try { JmsMessageID messageId = new JmsMessageID(messageSequence++, msg.getJMSMessageID()); Values vals = tupleProducer.toTuple(msg); collector.emit(vals, messageId); pendingAcks.put(messageId, msg); } catch (JMSException ex) { LOG.warn("Error processing message {}", msg); } }
throw new MessageConversionException( "Could not find type id property [" + this.typeIdPropertyName + "] on message [" + message.getJMSMessageID() + "] from destination [" + message.getJMSDestination() + "]");
private void sendMessage(MessageProducer producer, String threadName) throws Exception { Message message = createMessage(sentCount.get()); producer.send(message); if (LOG.isDebugEnabled()) { LOG.debug(threadName + " Sent: " + (message instanceof TextMessage ? ((TextMessage) message).getText() : message.getJMSMessageID())); } if (transactionBatchSize > 0 && sentCount.get() > 0 && sentCount.get() % transactionBatchSize == 0) { LOG.info(threadName + " Committing transaction: " + transactions++); session.commit(); } if (sleep > 0) { Thread.sleep(sleep); } }
/** * If the message is a {@link Message} then returns the JMS message ID. * Otherwise just return the first argument. * * @see org.springframework.retry.interceptor.MethodArgumentsKeyGenerator#getKey(Object[]) * * @throws UnexpectedInputException if the JMS id cannot be determined from * a JMS Message * @throws IllegalArgumentException if the arguments are empty */ @Override public Object getKey(Object[] items) { for (Object item : items) { if (item instanceof Message) { try { return ((Message) item).getJMSMessageID(); } catch (JMSException e) { throw new UnexpectedInputException("Could not extract message ID", e); } } } if (items.length == 0) { throw new IllegalArgumentException( "Method parameters are empty. The key generator cannot determine a unique key."); } return items[0]; }
/** * Create the invocation result response message. * <p>The default implementation creates a JMS ObjectMessage for the given * RemoteInvocationResult object. It sets the response's correlation id * to the request message's correlation id, if any; otherwise to the * request message id. * @param request the original request message * @param session the JMS session to use * @param result the invocation result * @return the message response to send * @throws javax.jms.JMSException if creating the message failed */ protected Message createResponseMessage(Message request, Session session, RemoteInvocationResult result) throws JMSException { Message response = this.messageConverter.toMessage(result, session); String correlation = request.getJMSCorrelationID(); if (correlation == null) { correlation = request.getJMSMessageID(); } response.setJMSCorrelationID(correlation); return response; }
sbuf.append(m.getJMSMessageID());
String messageId = jmsMessage.getJMSMessageID(); if (messageId != null) { headers.put(JmsHeaders.MESSAGE_ID, messageId);
@Override public void success(TransactionAttempt tx) { @SuppressWarnings("unchecked") List<Message> messages = (List<Message>) batchMessageMap.remove(tx.getTransactionId()); if (messages != null) { if (!messages.isEmpty()) { LOG.debug("Success for batch with transaction id " + tx.getTransactionId() + "/" + tx.getAttemptId() + " for " + name); } for (Message msg : messages) { String messageId = "UnknownId"; try { messageId = msg.getJMSMessageID(); msg.acknowledge(); LOG.trace("Acknowledged message " + messageId); } catch (JMSException e) { LOG.warn("Failed to acknowledge message " + messageId, e); } } } else { LOG.warn("No messages found in batch with transaction id " + tx.getTransactionId() + "/" + tx.getAttemptId()); } }
private Map<String, String> extractMessageHeaders(final Message message) throws JMSException { final Map<String, String> messageHeaders = new HashMap<>(); messageHeaders.put(JmsHeaders.DELIVERY_MODE, String.valueOf(message.getJMSDeliveryMode())); messageHeaders.put(JmsHeaders.EXPIRATION, String.valueOf(message.getJMSExpiration())); messageHeaders.put(JmsHeaders.PRIORITY, String.valueOf(message.getJMSPriority())); messageHeaders.put(JmsHeaders.REDELIVERED, String.valueOf(message.getJMSRedelivered())); messageHeaders.put(JmsHeaders.TIMESTAMP, String.valueOf(message.getJMSTimestamp())); messageHeaders.put(JmsHeaders.CORRELATION_ID, message.getJMSCorrelationID()); messageHeaders.put(JmsHeaders.MESSAGE_ID, message.getJMSMessageID()); messageHeaders.put(JmsHeaders.TYPE, message.getJMSType()); String replyToDestinationName = this.retrieveDestinationName(message.getJMSReplyTo(), JmsHeaders.REPLY_TO); if (replyToDestinationName != null) { messageHeaders.put(JmsHeaders.REPLY_TO, replyToDestinationName); } String destinationName = this.retrieveDestinationName(message.getJMSDestination(), JmsHeaders.DESTINATION); if (destinationName != null) { messageHeaders.put(JmsHeaders.DESTINATION, destinationName); } return messageHeaders; }
@Override public void onMessage(Message message) { try { Assert.assertNotNull(message); Assert.assertNotNull(message.getJMSMessageID()); if (consumedNum.incrementAndGet() == expectd && latch != null) { latch.countDown(); } } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void onMessage(Message message) { try { Assert.assertNotNull(message); Assert.assertNotNull(message.getJMSMessageID()); } catch (Exception e) { throw new RuntimeException(e); } } };
@Test public void testGetKeyFromMessage() throws Exception { Message message = mock(Message.class); when(message.getJMSMessageID()).thenReturn("foo"); JmsItemReader<Message> itemReader = new JmsItemReader<>(); itemReader.setItemType(Message.class); assertEquals("foo", methodArgumentsKeyGenerator.getKey(new Object[]{message})); }
retryTemplate.execute(callback, recoveryCallback, new DefaultRetryState(msg.getJMSMessageID()));
/** * Copies the standard JMS and user defined properties from the givem * message to the specified message * * @param fromMessage the message to take the properties from * @param toMessage the message to add the properties to * @throws JMSException */ public static void copyProperties(Message fromMessage, Message toMessage) throws JMSException { toMessage.setJMSMessageID(fromMessage.getJMSMessageID()); toMessage.setJMSCorrelationID(fromMessage.getJMSCorrelationID()); toMessage.setJMSReplyTo(transformDestination(fromMessage.getJMSReplyTo())); toMessage.setJMSDestination(transformDestination(fromMessage.getJMSDestination())); toMessage.setJMSDeliveryMode(fromMessage.getJMSDeliveryMode()); toMessage.setJMSRedelivered(fromMessage.getJMSRedelivered()); toMessage.setJMSType(fromMessage.getJMSType()); toMessage.setJMSExpiration(fromMessage.getJMSExpiration()); toMessage.setJMSPriority(fromMessage.getJMSPriority()); toMessage.setJMSTimestamp(fromMessage.getJMSTimestamp()); Enumeration propertyNames = fromMessage.getPropertyNames(); while (propertyNames.hasMoreElements()) { String name = propertyNames.nextElement().toString(); Object obj = fromMessage.getObjectProperty(name); toMessage.setObjectProperty(name, obj); } } }
@Test public void jmsReadOnlyPropertiesNotMapped() throws JMSException { Message<String> message = initBuilder() .setHeader(JmsHeaders.DESTINATION, new Destination() {}) .setHeader(JmsHeaders.DELIVERY_MODE, DeliveryMode.NON_PERSISTENT) .setHeader(JmsHeaders.EXPIRATION, 1000L) .setHeader(JmsHeaders.MESSAGE_ID, "abc-123") .setHeader(JmsHeaders.PRIORITY, 9) .setHeader(JmsHeaders.REDELIVERED, true) .setHeader(JmsHeaders.TIMESTAMP, System.currentTimeMillis()) .build(); javax.jms.Message jmsMessage = new StubTextMessage(); mapper.fromHeaders(message.getHeaders(), jmsMessage); assertNull(jmsMessage.getJMSDestination()); assertEquals(DeliveryMode.PERSISTENT, jmsMessage.getJMSDeliveryMode()); assertEquals(0, jmsMessage.getJMSExpiration()); assertNull(jmsMessage.getJMSMessageID()); assertEquals(javax.jms.Message.DEFAULT_PRIORITY, jmsMessage.getJMSPriority()); assertFalse(jmsMessage.getJMSRedelivered()); assertEquals(0, jmsMessage.getJMSTimestamp()); }