Example usage for org.springframework.integration.history MessageHistory write

List of usage examples for org.springframework.integration.history MessageHistory write

Introduction

In this page you can find the example usage for org.springframework.integration.history MessageHistory write.

Prototype

public static <T> Message<T> write(Message<T> message, NamedComponent component) 

Source Link

Usage

From source file:org.springframework.integration.channel.AbstractMessageChannel.java

/**
 * Send a message on this channel. If the channel is at capacity, this
 * method will block until either the timeout occurs or the sending thread
 * is interrupted. If the specified timeout is 0, the method will return
 * immediately. If less than zero, it will block indefinitely (see
 * {@link #send(Message)}).//from w  w  w.  j  a v a  2  s .co  m
 *
 * @param message the Message to send
 * @param timeout the timeout in milliseconds
 *
 * @return <code>true</code> if the message is sent successfully,
 * <code>false</code> if the message cannot be sent within the allotted
 * time or the sending thread is interrupted.
 */
public final boolean send(Message<?> message, long timeout) {
    Assert.notNull(message, "message must not be null");
    Assert.notNull(message.getPayload(), "message payload must not be null");
    if (this.shouldTrack) {
        message = MessageHistory.write(message, this);
    }
    message = this.convertPayloadIfNecessary(message);
    message = this.interceptors.preSend(message, this);
    if (message == null) {
        return false;
    }
    try {
        boolean sent = this.doSend(message, timeout);
        this.interceptors.postSend(message, this, sent);
        return sent;
    } catch (Exception e) {
        if (e instanceof MessagingException) {
            throw (MessagingException) e;
        }
        throw new MessageDeliveryException(message,
                "failed to send Message to channel '" + this.getComponentName() + "'", e);
    }
}

From source file:org.springframework.integration.handler.AbstractMessageHandler.java

public final void handleMessage(Message<?> message) {
    Assert.notNull(message, "Message must not be null");
    Assert.notNull(message.getPayload(), "Message payload must not be null");
    if (this.logger.isDebugEnabled()) {
        this.logger.debug(this + " received message: " + message);
    }/*from  w  w w  .  j  a v a 2  s .  c  om*/
    try {
        if (message != null && this.shouldTrack) {
            message = MessageHistory.write(message, this);
        }
        this.handleMessageInternal(message);
    } catch (Exception e) {
        if (e instanceof MessagingException) {
            throw (MessagingException) e;
        }
        throw new MessageHandlingException(message, "error occurred in message handler [" + this + "]", e);
    }
}

From source file:org.springframework.integration.jdbc.JdbcMessageStoreTests.java

@Test
@Transactional/*w  ww .j ava2  s  . com*/
public void testWithMessageHistory() throws Exception {

    Message<?> message = new GenericMessage<String>("Hello");
    DirectChannel fooChannel = new DirectChannel();
    fooChannel.setBeanName("fooChannel");
    DirectChannel barChannel = new DirectChannel();
    barChannel.setBeanName("barChannel");

    message = MessageHistory.write(message, fooChannel);
    message = MessageHistory.write(message, barChannel);
    messageStore.addMessage(message);
    message = messageStore.getMessage(message.getHeaders().getId());
    MessageHistory messageHistory = MessageHistory.read(message);
    assertNotNull(messageHistory);
    assertEquals(2, messageHistory.size());
    Properties fooChannelHistory = messageHistory.get(0);
    assertEquals("fooChannel", fooChannelHistory.get("name"));
    assertEquals("channel", fooChannelHistory.get("type"));
}