Example usage for org.springframework.jms.core MessagePostProcessor MessagePostProcessor

List of usage examples for org.springframework.jms.core MessagePostProcessor MessagePostProcessor

Introduction

In this page you can find the example usage for org.springframework.jms.core MessagePostProcessor MessagePostProcessor.

Prototype

MessagePostProcessor

Source Link

Usage

From source file:com.kinglcc.spring.jms.JmsService.java

public <T> void send(final String destinaionName, final String messageGroup, T message) {
    jmsTemplate.convertAndSend(destinaionName, message, new MessagePostProcessor() {

        @Override/*from w  w w  .j av a2 s.co m*/
        public Message postProcessMessage(Message message) throws JMSException {
            message.setJMSType(messageGroup);
            return message;
        }
    });
}

From source file:org.appverse.web.framework.backend.messaging.services.integration.impl.live.JMSSyncService.java

@Override
public void send(final T dto) throws Exception {
    this.getTemplatePublisher().convertAndSend(dto, new MessagePostProcessor() {
        @Override/*  w w  w  .j  av a  2  s  . c  o  m*/
        public Message postProcessMessage(final Message message) throws JMSException {
            if (logger.isDebugEnabled()) {
                logger.debug("***** SENDING MESSAGE ******");
                traceMessage(message);
            }
            return message;
        }
    });
}

From source file:org.appverse.web.framework.backend.messaging.services.integration.impl.live.JMSSyncService.java

@Override
public void send(final T dto, final AbstractIntegrationBean header) throws Exception {

    this.getTemplatePublisher().convertAndSend(dto, new MessagePostProcessor() {
        @Override/*from  w  w  w  .j  av a  2 s . c  o  m*/
        public Message postProcessMessage(final Message message) throws JMSException {
            // overwrite in Repositories
            fillHeader(message, header);
            if (logger.isDebugEnabled()) {
                logger.debug("***** SENDING MESSAGE WITH HEADER******");
                traceMessage(message);
            }
            return message;
        }
    });

}

From source file:org.nebulaframework.grid.cluster.manager.services.jobs.splitaggregate.SplitterServiceImpl.java

/**
 * Enqueues a given Task with in the {@code TaskQueue}.
 * //from  w  ww  .j av a  2s. co  m
 * @param jobId String JobId
 * @param taskId int TaskId (Sequence Number of Task)
 * @param task {@code GridTask} task
 */
private void enqueueTask(final GridJobProfile profile, final int taskId, GridTask<?> task) {

    final String jobId = profile.getJobId();

    // Send GridTask as a JMS Object Message to TaskQueue
    jmsTemplate.convertAndSend(JMSNamingSupport.getTaskQueueName(jobId), task, new MessagePostProcessor() {

        public Message postProcessMessage(Message message) throws JMSException {

            // Post Process to include Meta Data
            message.setJMSCorrelationID(jobId); // Set Correlation ID to Job Id
            message.setIntProperty("taskId", taskId); // Put taskId as a property
            log.debug("Enqueued Task : " + taskId);
            return message;
        }
    });

    profile.getTaskTracker().taskEnqueued(taskId);
}

From source file:org.nebulaframework.grid.cluster.manager.services.jobs.unbounded.UnboundedJobProcessor.java

/**
 * Enqueues a given Task with in the {@code TaskQueue}.
 * /* w  w  w .  j  a  va2s  . c  o m*/
 * @param jobId
 *            String JobId
 * @param taskId
 *            int TaskId (Sequence Number of Task)
 * @param task
 *            {@code GridTask} task
 */
private void enqueueTask(final String jobId, final int taskId, GridTask<?> task) {

    String queueName = JMSNamingSupport.getTaskQueueName(jobId);

    // Post Process to include Meta Data
    MessagePostProcessor postProcessor = new MessagePostProcessor() {

        public Message postProcessMessage(Message message) throws JMSException {

            // Set Correlation ID to Job Id
            message.setJMSCorrelationID(jobId);

            // Put taskId as a property
            message.setIntProperty("taskId", taskId);

            log.debug("Enqueued Task : " + taskId);

            return message;
        }
    };

    // Send GridTask as a JMS Object Message to TaskQueue
    jmsTemplate.convertAndSend(queueName, task, postProcessor);

    // Update Task Tracker
    profile.getTaskTracker().taskEnqueued(taskId);

}

From source file:org.openengsb.ports.jms.JMSIncomingPort.java

public void start() {
    simpleMessageListenerContainer = createListenerContainer(receive, new MessageListener() {
        @Override//from w  w  w. j av  a 2s  .c om
        public void onMessage(Message message) {
            LOGGER.trace("JMS-message recieved. Checking if the type is supported");
            if (!(message instanceof TextMessage)) {
                LOGGER.debug("Received JMS-message is not type of text message.");
                return;
            }
            LOGGER.trace("Received a text message and start parsing");
            TextMessage textMessage = (TextMessage) message;
            String textContent = extractTextFromMessage(textMessage);
            HashMap<String, Object> metadata = new HashMap<String, Object>();
            String result = null;
            try {
                LOGGER.debug("starting filterchain for incoming message");
                result = (String) getFilterChainToUse().filter(textContent, metadata);
            } catch (Exception e) {
                LOGGER.error("an error occured when processing the filterchain", e);
                result = ExceptionUtils.getStackTrace(e);
            }
            Destination replyQueue;
            final String correlationID;
            try {
                if (message.getJMSCorrelationID() == null) {
                    correlationID = message.getJMSMessageID();
                } else {
                    correlationID = message.getJMSCorrelationID();
                }
                replyQueue = message.getJMSReplyTo();
            } catch (JMSException e) {
                LOGGER.warn("error when getting destination queue or correlationid from client message: {}", e);
                return;
            }
            if (replyQueue == null) {
                LOGGER.warn("no replyTo destination specifyed could not send response");
                return;
            }

            new JmsTemplate(connectionFactory).convertAndSend(replyQueue, result, new MessagePostProcessor() {
                @Override
                public Message postProcessMessage(Message message) throws JMSException {
                    message.setJMSCorrelationID(correlationID);
                    return message;
                }
            });
        }

        private String extractTextFromMessage(TextMessage textMessage) {
            try {
                return textMessage.getText();
            } catch (JMSException e) {
                throw new IllegalStateException("Couldn't extract text from jms message", e);
            }
        }

    });
    simpleMessageListenerContainer.start();
}

From source file:org.springframework.cloud.stream.binder.jms.utils.RepublishMessageRecoverer.java

@Override
public void recover(Message undeliveredMessage, Throwable cause) {
    String deadLetterQueueName = queueProvisioner.provisionDeadLetterQueue();

    final JmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
    MessageConverter converter = new SimpleMessageConverter();
    Object payload = null;//ww w  .ja v  a2  s . co m

    try {
        payload = converter.fromMessage(undeliveredMessage);
    } catch (JMSException e) {
        logger.error("The message payload could not be retrieved. It will be lost.", e);
    }

    final Map<String, Object> headers = mapper.toHeaders(undeliveredMessage);
    headers.put(X_EXCEPTION_STACKTRACE, getStackTraceAsString(cause));
    headers.put(X_EXCEPTION_MESSAGE,
            cause.getCause() != null ? cause.getCause().getMessage() : cause.getMessage());
    try {
        headers.put(X_ORIGINAL_QUEUE, undeliveredMessage.getJMSDestination().toString());
    } catch (JMSException e) {
        logger.error("The message destination could not be retrieved", e);
    }
    Map<? extends String, ? extends Object> additionalHeaders = additionalHeaders(undeliveredMessage, cause);
    if (additionalHeaders != null) {
        headers.putAll(additionalHeaders);
    }

    jmsTemplate.convertAndSend(deadLetterQueueName, payload, new MessagePostProcessor() {
        @Override
        public Message postProcessMessage(Message message) throws JMSException {
            mapper.fromHeaders(new MessageHeaders(headers), message);
            return message;
        }
    });

}