List of usage examples for javax.jms Message getJMSRedelivered
boolean getJMSRedelivered() throws JMSException;
From source file:com.egt.core.aplicacion.Bitacora.java
public static void traceMessage(Class clase, String metodo, Message message) throws JMSException { logTrace(Utils.getTraceMessageFormat(getCallingMethodStackTraceElementTrack(clase, metodo, 4), new Object[] { message.getJMSType(), message.getJMSMessageID(), message.getJMSCorrelationID(), message.getJMSRedelivered() })); }
From source file:eu.planets_project.tb.impl.system.batch.listener.BatchExperimentListenerImpl.java
public void doOnMessage(Message m, long timeOutMillis, Thread thread) { log.debug("BatchExecutionListener: doOnMessage"); //1.check if message got redelivered before doing any processing try {// w w w . ja v a2s . co m if (m.getJMSRedelivered()) { log.debug( "BatchExperimentListener_shortTimeout: onMessage: re-receive message from the queue. Not processing it"); return; } } catch (JMSException e) { log.debug(e); return; } //2. extract the message: it contains the ticket for identifying the job on the workflow system TextMessage msg = null; String ticket = ""; String batchProcessorID = ""; if (m instanceof TextMessage) { msg = (TextMessage) m; try { ticket = msg.getText(); batchProcessorID = msg.getStringProperty(BatchProcessor.QUEUE_PROPERTY_NAME_FOR_SENDING); log.debug("BatchExperimentListener_shortTimeout: received message at timestamp: " + msg.getJMSTimestamp() + " for ticket: " + ticket + "on batch processor: " + batchProcessorID); } catch (JMSException e) { log.debug(e); return; } } else { return; } //3. get the BatchProcessing system that's notified TestbedBatchProcessorManager batchManager = TestbedBatchProcessorManager.getInstance(); BatchProcessor bp = batchManager.getBatchProcessor(batchProcessorID); //check rollback and if batch processor has persistent jobs if ((bp.getJob(ticket) == null) || (bp.getJobStatus(ticket).equals(TestbedBatchJob.NO_SUCH_JOB))) { log.debug("EJBTransactionRollback - BatchProcessor no persistent job - dropp job: " + ticket); return; } //4. check for updates and store extracted information in experiment long t0 = System.currentTimeMillis(); long t1 = System.currentTimeMillis(); boolean bInfomredStarted = false; //do until we have reached our time-out time or completed while (t1 - t0 < timeOutMillis) { //a) check started //use batchProcessor specific implementation for checking on this. boolean bStarted = bp.isStarted(ticket); if (bStarted) { if (!bInfomredStarted) { //callback: inform once about started bp.notifyStart(ticket, bp.getJob(ticket)); log.debug("BatchExecutionListener: notify STARTED for: " + ticket); bInfomredStarted = true; } if (bp.isRunning(ticket)) { TestbedBatchJob job = bp.getJob(ticket); job.setStatus(TestbedBatchJob.RUNNING); bp.notifyRunning(ticket, job); log.debug("BatchExecutionListener: notify RUNNING for: " + ticket); } if (bp.isUpdated(ticket)) { bp.notifyUpdate(ticket, bp.getJob(ticket)); log.debug("BatchExecutionListener: notify UPDATE for: " + ticket); } if (bp.isFailed(ticket)) { TestbedBatchJob job = bp.getJob(ticket); job.setStatus(TestbedBatchJob.FAILED); bp.notifyFailed(ticket, job); log.debug("BatchExecutionListener: notify FAILED for: " + ticket); } //check if completed if (bp.isCompleted(ticket)) { TestbedBatchJob job = bp.getJob(ticket); job.setStatus(TestbedBatchJob.DONE); bp.notifyComplete(ticket, job); log.debug("BatchExecutionListener: notify COMPLETE for: " + ticket); return; } } //status is: still no completed - sleep and repoll try { Thread.sleep(sleep); } catch (InterruptedException e) { log.debug("Error while waiting for ticket: " + ticket, e); TestbedBatchJob job = bp.getJob(ticket); job.setStatus(TestbedBatchJob.FAILED); bp.notifyFailed(ticket, job); return; } t1 = System.currentTimeMillis(); } //b) in this case a time-out occurred TestbedBatchJob job = bp.getJob(ticket); job.setStatus(TestbedBatchJob.FAILED); job.setWorkflowFailureReport(new String("BatchExperimentListener with timeout of " + timeOutMillis / 1000 + " Sec. has timed-out. This normally indicates a failure within the remote workflow execution processor")); bp.notifyFailed(ticket, job); log.debug("BatchExecutionListener: notify FAILED due to time-out for: " + ticket); }
From source file:org.apigw.monitoring.jms.messagelistener.MonitoringMessageListener.java
@Override public void onMessage(final Message message) { String textMessage = null;//from w w w .j a va 2 s. com try { textMessage = ((TextMessage) message).getText(); log.debug("Monitoring message: " + textMessage); if (message.getJMSRedelivered()) { log.debug("Detected a redelivered message with payload: " + textMessage); if (isMessageAlreadyPersisted(textMessage)) { return; //Finish the JMS transaction without persisting any message } //Otherwise just continue business as usual as we want to consume this message } if (isResourceEvent(textMessage)) { ResourceEvent event = parseJSONToResourceEvent(textMessage); if (event != null) resourceEventRepository.save(event); } else { //If not a resource event, then it must be a AuthEvent AuthEvent event = parseJSONToAuthEvent(textMessage); if (event != null) authEventRepository.save(event); } } catch (JMSException e) { log.error(e.getMessage()); log.debug("Rethrowing a JMSException as a RuntimeException in order to get a redelivery"); throw new RuntimeException(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); log.debug("Rethrowing a JMSException as a RuntimeException in order to get a redelivery"); } }
From source file:com.datatorrent.lib.io.jms.AbstractJMSInputOperator.java
/** * This method is called when a message is added to {@link #holdingBuffer} and can be overwritten by subclasses * if required. This is called by the JMS thread not Operator thread. * * @param message/*from w ww . j a v a 2s .c o m*/ * @return message is accepted. * @throws javax.jms.JMSException */ protected boolean messageConsumed(Message message) throws JMSException { if (message.getJMSRedelivered() && pendingAck.contains(message.getJMSMessageID())) { counters.getCounter(CounterKeys.REDELIVERED).increment(); LOG.warn("IGNORING: Redelivered Message {}", message.getJMSMessageID()); return false; } pendingAck.add(message.getJMSMessageID()); MutableLong receivedCt = counters.getCounter(CounterKeys.RECEIVED); receivedCt.increment(); LOG.debug("message id: {} buffer size: {} received: {}", message.getJMSMessageID(), holdingBuffer.size(), receivedCt.longValue()); return true; }
From source file:com.jmstoolkit.beans.MessageTableModel.java
/** * * @param message/*from w ww .jav a 2 s . c o m*/ */ @Override public void onMessage(Message message) { LOGGER.log(Level.FINE, "Message Received"); messagesReceived++; try { MessageTableRecord qRecord = new MessageTableRecord(); qRecord.setJMSCorrelationID(message.getJMSCorrelationID()); qRecord.setJMSDeliveryMode(message.getJMSDeliveryMode()); qRecord.setJMSExpiration(message.getJMSExpiration()); qRecord.setJMSMessageID(message.getJMSMessageID()); qRecord.setJMSTimestamp(message.getJMSTimestamp()); qRecord.setJMSType(message.getJMSType()); qRecord.setJMSDestination(message.getJMSDestination()); qRecord.setJMSCorrelationIDAsBytes(message.getJMSCorrelationIDAsBytes()); qRecord.setJMSPriority(message.getJMSPriority()); qRecord.setJMSType(message.getJMSType()); qRecord.setJMSReplyTo(message.getJMSReplyTo()); qRecord.setJMSRedelivered(message.getJMSRedelivered()); Enumeration pEnumerator = message.getPropertyNames(); Properties props = new Properties(); while (pEnumerator.hasMoreElements()) { String pElement = (String) pEnumerator.nextElement(); props.put(pElement, message.getStringProperty(pElement)); } qRecord.setProperties(props); if (message instanceof TextMessage) { qRecord.setText(((TextMessage) message).getText()); } if (message instanceof ObjectMessage) { qRecord.setObject(((ObjectMessage) message).getObject()); } List newData = data; newData.add(qRecord); this.setData(newData); } catch (JMSException e) { LOGGER.log(Level.WARNING, "JMS problem", e); } }
From source file:com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingWorker.java
private static String formatHeaders(Message message) { Destination dest = null;/*w ww.j av a 2s . co m*/ int delMode = 0; long expiration = 0; Time expTime = null; int priority = 0; String msgID = null; long timestamp = 0; Time timestampTime = null; String correlID = null; Destination replyTo = null; boolean redelivered = false; String type = null; StringBuilder sb = new StringBuilder(); try { try { dest = message.getJMSDestination(); sb.append(" JMSDestination: "); sb.append(dest); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSDestination header\n", e); } try { delMode = message.getJMSDeliveryMode(); if (delMode == DeliveryMode.NON_PERSISTENT) { sb.append(" JMSDeliveryMode: non-persistent\n"); } else if (delMode == DeliveryMode.PERSISTENT) { sb.append(" JMSDeliveryMode: persistent\n"); } else { sb.append(" JMSDeliveryMode: neither persistent nor non-persistent; error\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSDeliveryMode header\n", e); } try { expiration = message.getJMSExpiration(); if (expiration != 0) { expTime = new Time(expiration); sb.append(" JMSExpiration: "); sb.append(expTime); sb.append("\n"); } else { sb.append(" JMSExpiration: 0\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSExpiration header\n", e); } try { priority = message.getJMSPriority(); sb.append(" JMSPriority: "); sb.append(priority); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSPriority header\n", e); } try { msgID = message.getJMSMessageID(); sb.append(" JMSMessageID: "); sb.append(msgID); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSMessageID header\n", e); } try { timestamp = message.getJMSTimestamp(); if (timestamp != 0) { timestampTime = new Time(timestamp); sb.append(" JMSTimestamp: "); sb.append(timestampTime); sb.append("\n"); } else { sb.append(" JMSTimestamp: 0\n"); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSTimestamp header\n", e); } try { correlID = message.getJMSCorrelationID(); sb.append(" JMSCorrelationID: "); sb.append(correlID); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSCorrelationID header\n", e); } try { replyTo = message.getJMSReplyTo(); sb.append(" JMSReplyTo: "); sb.append(replyTo); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSReplyTo header\n", e); } try { redelivered = message.getJMSRedelivered(); sb.append(" JMSRedelivered: "); sb.append(redelivered); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSRedelivered header\n", e); } try { type = message.getJMSType(); sb.append(" JMSType: "); sb.append(type); sb.append("\n"); } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMSType header\n", e); } } catch (Exception e) { log.log(Level.WARNING, "Unable to generate JMS headers\n", e); } return sb.toString(); }
From source file:hermes.impl.DefaultXMLHelper.java
public XMLMessage createXMLMessage(ObjectFactory factory, Message message) throws JMSException, IOException, EncoderException { try {/* w w w . ja va 2 s. c o m*/ XMLMessage rval = factory.createXMLMessage(); if (message instanceof TextMessage) { rval = factory.createXMLTextMessage(); XMLTextMessage textRval = (XMLTextMessage) rval; TextMessage textMessage = (TextMessage) message; if (isBase64EncodeTextMessages()) { byte[] bytes = base64EncoderTL.get().encode(textMessage.getText().getBytes()); textRval.setText(new String(bytes, "ASCII")); textRval.setCodec(BASE64_CODEC); } else { textRval.setText(textMessage.getText()); } } else if (message instanceof MapMessage) { rval = factory.createXMLMapMessage(); XMLMapMessage mapRval = (XMLMapMessage) rval; MapMessage mapMessage = (MapMessage) message; for (Enumeration iter = mapMessage.getMapNames(); iter.hasMoreElements();) { String propertyName = (String) iter.nextElement(); Object propertyValue = mapMessage.getObject(propertyName); Property xmlProperty = factory.createProperty(); if (propertyValue != null) { xmlProperty.setValue(propertyValue.toString()); xmlProperty.setType(propertyValue.getClass().getName()); } xmlProperty.setName(propertyName); mapRval.getBodyProperty().add(xmlProperty); } } else if (message instanceof BytesMessage) { rval = factory.createXMLBytesMessage(); XMLBytesMessage bytesRval = (XMLBytesMessage) rval; BytesMessage bytesMessage = (BytesMessage) message; ByteArrayOutputStream bosream = new ByteArrayOutputStream(); bytesMessage.reset(); try { for (;;) { bosream.write(bytesMessage.readByte()); } } catch (MessageEOFException ex) { // NOP } bytesRval.setBytes(new String(base64EncoderTL.get().encode(bosream.toByteArray()))); } else if (message instanceof ObjectMessage) { rval = factory.createXMLObjectMessage(); XMLObjectMessage objectRval = (XMLObjectMessage) rval; ObjectMessage objectMessage = (ObjectMessage) message; ByteArrayOutputStream bostream = new ByteArrayOutputStream(); ObjectOutputStream oostream = new ObjectOutputStream(bostream); oostream.writeObject(objectMessage.getObject()); oostream.flush(); byte b[] = base64EncoderTL.get().encode(bostream.toByteArray()); String s = new String(b, "ASCII"); objectRval.setObject(s); } if (message.getJMSReplyTo() != null) { rval.setJMSReplyTo(JMSUtils.getDestinationName(message.getJMSReplyTo())); rval.setJMSReplyToDomain(Domain.getDomain(message.getJMSReplyTo()).getId()); } // try/catch each individually as we sometime find some JMS // providers // can barf try { rval.setJMSDeliveryMode(message.getJMSDeliveryMode()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { rval.setJMSExpiration(message.getJMSExpiration()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { rval.setJMSMessageID(message.getJMSMessageID()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { rval.setJMSPriority(message.getJMSPriority()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { rval.setJMSRedelivered(message.getJMSRedelivered()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } catch (IllegalStateException ex) { // http://hermesjms.com/forum/viewtopic.php?f=4&t=346 log.error(ex.getMessage(), ex); } try { rval.setJMSTimestamp(message.getJMSTimestamp()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { rval.setJMSType(message.getJMSType()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { rval.setJMSCorrelationID(message.getJMSCorrelationID()); } catch (JMSException ex) { log.error(ex.getMessage(), ex); } try { if (message.getJMSDestination() != null) { rval.setJMSDestination(JMSUtils.getDestinationName(message.getJMSDestination())); rval.setFromQueue(JMSUtils.isQueue(message.getJMSDestination())); } } catch (JMSException ex) { log.error(ex.getMessage(), ex); } for (final Enumeration iter = message.getPropertyNames(); iter.hasMoreElements();) { String propertyName = (String) iter.nextElement(); if (!propertyName.startsWith("JMS")) { Object propertyValue = message.getObjectProperty(propertyName); Property property = factory.createProperty(); property.setName(propertyName); if (propertyValue != null) { property.setValue(StringEscapeUtils.escapeXml(propertyValue.toString())); property.setType(propertyValue.getClass().getName()); } rval.getHeaderProperty().add(property); } } return rval; } catch (Exception ex) { throw new HermesException(ex); } }
From source file:org.apache.activemq.bugs.AMQ6133PersistJMSRedeliveryTest.java
private void consumerAndRollback(int iteration) throws Exception { Connection connection = createConnection(); Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); Queue queue = session.createQueue(QUEUE_NAME); MessageConsumer consumer = session.createConsumer(queue); long msgCount = getProxyToQueue(queue.getQueueName()).getQueueSize(); for (int i = 0; i < msgCount; ++i) { Message message = consumer.receive(50000); assertNotNull(message);/*from w ww .jav a2 s. com*/ if (iteration > 0) { assertTrue(message.getJMSRedelivered()); } } connection.close(); }
From source file:org.apache.axis2.transport.jms.JMSMessageReceiver.java
/** * Process a new message received//from w ww. jav a2s . co m * * @param message the JMS message received * @param ut UserTransaction which was used to receive the message * @return true if caller should commit */ public boolean onMessage(Message message, UserTransaction ut) { try { if (log.isDebugEnabled()) { StringBuffer sb = new StringBuffer(); sb.append("Received new JMS message for service :").append(endpoint.getServiceName()); sb.append("\nDestination : ").append(message.getJMSDestination()); sb.append("\nMessage ID : ").append(message.getJMSMessageID()); sb.append("\nCorrelation ID : ").append(message.getJMSCorrelationID()); sb.append("\nReplyTo : ").append(message.getJMSReplyTo()); sb.append("\nRedelivery ? : ").append(message.getJMSRedelivered()); sb.append("\nPriority : ").append(message.getJMSPriority()); sb.append("\nExpiration : ").append(message.getJMSExpiration()); sb.append("\nTimestamp : ").append(message.getJMSTimestamp()); sb.append("\nMessage Type : ").append(message.getJMSType()); sb.append("\nPersistent ? : ").append(DeliveryMode.PERSISTENT == message.getJMSDeliveryMode()); log.debug(sb.toString()); if (log.isTraceEnabled() && message instanceof TextMessage) { log.trace("\nMessage : " + ((TextMessage) message).getText()); } } } catch (JMSException e) { if (log.isDebugEnabled()) { log.debug("Error reading JMS message headers for debug logging", e); } } // update transport level metrics try { metrics.incrementBytesReceived(JMSUtils.getMessageSize(message)); } catch (JMSException e) { log.warn("Error reading JMS message size to update transport metrics", e); } // has this message already expired? expiration time == 0 means never expires // TODO: explain why this is necessary; normally it is the responsibility of the provider to handle message expiration try { long expiryTime = message.getJMSExpiration(); if (expiryTime > 0 && System.currentTimeMillis() > expiryTime) { if (log.isDebugEnabled()) { log.debug("Discard expired message with ID : " + message.getJMSMessageID()); } return true; } } catch (JMSException ignore) { } boolean successful = false; try { successful = processThoughEngine(message, ut); } catch (JMSException e) { log.error("JMS Exception encountered while processing", e); } catch (AxisFault e) { log.error("Axis fault processing message", e); } catch (Exception e) { log.error("Unknown error processing message", e); } finally { if (successful) { metrics.incrementMessagesReceived(); } else { metrics.incrementFaultsReceiving(); } } return successful; }
From source file:org.apache.axis2.transport.jms.JMSUtils.java
/** * Extract transport level headers for JMS from the given message into a Map * * @param message the JMS message//from w ww . j a va2s . c o m * @return a Map of the transport headers */ public static Map<String, Object> getTransportHeaders(Message message) { // create a Map to hold transport headers Map<String, Object> map = new HashMap<String, Object>(); // correlation ID try { if (message.getJMSCorrelationID() != null) { map.put(JMSConstants.JMS_COORELATION_ID, message.getJMSCorrelationID()); } } catch (JMSException ignore) { } // set the delivery mode as persistent or not try { map.put(JMSConstants.JMS_DELIVERY_MODE, Integer.toString(message.getJMSDeliveryMode())); } catch (JMSException ignore) { } // destination name try { if (message.getJMSDestination() != null) { Destination dest = message.getJMSDestination(); map.put(JMSConstants.JMS_DESTINATION, dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName()); } } catch (JMSException ignore) { } // expiration try { map.put(JMSConstants.JMS_EXPIRATION, Long.toString(message.getJMSExpiration())); } catch (JMSException ignore) { } // if a JMS message ID is found try { if (message.getJMSMessageID() != null) { map.put(JMSConstants.JMS_MESSAGE_ID, message.getJMSMessageID()); } } catch (JMSException ignore) { } // priority try { map.put(JMSConstants.JMS_PRIORITY, Long.toString(message.getJMSPriority())); } catch (JMSException ignore) { } // redelivered try { map.put(JMSConstants.JMS_REDELIVERED, Boolean.toString(message.getJMSRedelivered())); } catch (JMSException ignore) { } // replyto destination name try { if (message.getJMSReplyTo() != null) { Destination dest = message.getJMSReplyTo(); map.put(JMSConstants.JMS_REPLY_TO, dest instanceof Queue ? ((Queue) dest).getQueueName() : ((Topic) dest).getTopicName()); } } catch (JMSException ignore) { } // priority try { map.put(JMSConstants.JMS_TIMESTAMP, Long.toString(message.getJMSTimestamp())); } catch (JMSException ignore) { } // message type try { if (message.getJMSType() != null) { map.put(JMSConstants.JMS_TYPE, message.getJMSType()); } } catch (JMSException ignore) { } // any other transport properties / headers Enumeration<?> e = null; try { e = message.getPropertyNames(); } catch (JMSException ignore) { } if (e != null) { while (e.hasMoreElements()) { String headerName = (String) e.nextElement(); try { map.put(headerName, message.getStringProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getBooleanProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getIntProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getLongProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getDoubleProperty(headerName)); continue; } catch (JMSException ignore) { } try { map.put(headerName, message.getFloatProperty(headerName)); } catch (JMSException ignore) { } } } return map; }