Example usage for org.springframework.messaging MessageDeliveryException MessageDeliveryException

List of usage examples for org.springframework.messaging MessageDeliveryException MessageDeliveryException

Introduction

In this page you can find the example usage for org.springframework.messaging MessageDeliveryException MessageDeliveryException.

Prototype

public MessageDeliveryException(Message<?> message, Throwable cause) 

Source Link

Usage

From source file:ch.rasc.wampspring.EventMessenger.java

/**
 * Send an EventMessage to the {@link SimpleBrokerMessageHandler}. The broker looks up
 * if the receiver of the message ({@link EventMessage#getWebSocketSessionId()}) is
 * subscribed to the destination ({@link EventMessage#getDestination()}). If the
 * receiver is subscribed the broker sends the message to him.
 *
 * @param eventMessage The event message
 *///from w  w  w.ja va2s.c  o  m
public void send(EventMessage eventMessage) {
    long timeout = this.sendTimeout;
    boolean sent = timeout >= 0 ? this.brokerChannel.send(eventMessage, timeout)
            : this.brokerChannel.send(eventMessage);

    if (!sent) {
        throw new MessageDeliveryException(eventMessage, "Failed to send message with destination '"
                + eventMessage.getDestination() + "' within timeout: " + timeout);
    }
}

From source file:ch.rasc.wampspring.EventMessenger.java

/**
 * Send an EventMessage directly to the client (
 * {@link EventMessage#getWebSocketSessionId()}).
 * <p>//  w w  w.  j  ava2  s .c om
 * In contrast to {@link #send(EventMessage)} this method does not check if the
 * receiver is subscribed to the destination. The {@link SimpleBrokerMessageHandler}
 * is not involved in sending this message.
 *
 * @param eventMessage The event message
 *
 * @see #send(EventMessage)
 */
public void sendDirect(EventMessage eventMessage) {
    Assert.notNull(eventMessage.getWebSocketSessionId(), "WebSocket session id must not be null");

    long timeout = this.sendTimeout;
    boolean sent = timeout >= 0 ? this.clientOutboundChannel.send(eventMessage, timeout)
            : this.clientOutboundChannel.send(eventMessage);

    if (!sent) {
        throw new MessageDeliveryException(eventMessage, "Failed to direct send message with destination '"
                + eventMessage.getDestination() + "' within timeout: " + timeout);
    }
}

From source file:ch.rasc.wampspring.method.WampAnnotationMethodMessageHandler.java

public void send(WampMessage wampMessage) {
    long timeout = this.sendTimeout;
    boolean sent = timeout >= 0 ? this.clientOutboundChannel.send(wampMessage, timeout)
            : this.clientOutboundChannel.send(wampMessage);

    if (!sent) {//from  w  w  w  .  j a  va 2  s.c om
        throw new MessageDeliveryException(wampMessage, "Failed to send message with destination '"
                + wampMessage.getDestination() + "' within timeout: " + timeout);
    }
}

From source file:org.springframework.integration.jms.JmsOutboundGateway.java

private Destination determineRequestDestination(Message<?> message, Session session) throws JMSException {
    if (this.requestDestination != null) {
        return this.requestDestination;
    }/*from  w  ww.  ja  va  2  s  .c o  m*/
    if (this.requestDestinationName != null) {
        return this.resolveRequestDestination(this.requestDestinationName, session);
    }
    if (this.requestDestinationExpressionProcessor != null) {
        Object result = this.requestDestinationExpressionProcessor.processMessage(message);
        if (result instanceof Destination) {
            return (Destination) result;
        }
        if (result instanceof String) {
            return this.resolveRequestDestination((String) result, session);
        }
        throw new MessageDeliveryException(message, "Evaluation of requestDestinationExpression failed "
                + "to produce a Destination or destination name. Result was: " + result);
    }
    throw new MessageDeliveryException(message,
            "No requestDestination, requestDestinationName, or requestDestinationExpression has been configured.");
}

From source file:org.springframework.integration.jms.JmsOutboundGateway.java

private Destination determineReplyDestination(Message<?> message, Session session) throws JMSException {
    if (this.replyDestination != null) {
        return this.replyDestination;
    }//from  w  w  w .  ja  v  a2s .  c o  m
    if (this.replyDestinationName != null) {
        return this.resolveReplyDestination(this.replyDestinationName, session);
    }
    if (this.replyDestinationExpressionProcessor != null) {
        Object result = this.replyDestinationExpressionProcessor.processMessage(message);
        if (result instanceof Destination) {
            return (Destination) result;
        }
        if (result instanceof String) {
            return this.resolveReplyDestination((String) result, session);
        }
        throw new MessageDeliveryException(message,
                "Evaluation of replyDestinationExpression failed to produce a Destination or destination name. "
                        + "Result was: " + result);
    }
    return session.createTemporaryQueue();
}

From source file:org.springframework.messaging.core.GenericMessagingTemplate.java

protected final void doSend(MessageChannel channel, Message<?> message, long timeout) {
    Assert.notNull(channel, "MessageChannel is required");

    Message<?> messageToSend = message;
    MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
    if (accessor != null && accessor.isMutable()) {
        accessor.removeHeader(this.sendTimeoutHeader);
        accessor.removeHeader(this.receiveTimeoutHeader);
        accessor.setImmutable();//from ww  w . j a  va 2s.  co  m
    } else if (message.getHeaders().containsKey(this.sendTimeoutHeader)
            || message.getHeaders().containsKey(this.receiveTimeoutHeader)) {
        messageToSend = MessageBuilder.fromMessage(message).setHeader(this.sendTimeoutHeader, null)
                .setHeader(this.receiveTimeoutHeader, null).build();
    }

    boolean sent = (timeout >= 0 ? channel.send(messageToSend, timeout) : channel.send(messageToSend));

    if (!sent) {
        throw new MessageDeliveryException(message,
                "Failed to send message to channel '" + channel + "' within timeout: " + timeout);
    }
}

From source file:org.springframework.messaging.simp.stomp.DefaultStompSession.java

private void execute(Message<byte[]> message) {
    if (logger.isTraceEnabled()) {
        StompHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
        if (accessor != null) {
            logger.trace("Sending " + accessor.getDetailedLogMessage(message.getPayload()));
        }// ww w  .ja  v a 2 s . c o  m
    }
    TcpConnection<byte[]> conn = this.connection;
    Assert.state(conn != null, "Connection closed");
    try {
        conn.send(message).get();
    } catch (ExecutionException ex) {
        throw new MessageDeliveryException(message, ex.getCause());
    } catch (Throwable ex) {
        throw new MessageDeliveryException(message, ex);
    }
}

From source file:org.springframework.yarn.integration.IntegrationAppmasterService.java

/**
 * Send the message to the given channel. The channel must be a String or
 * {@link MessageChannel} instance, never <code>null</code>.
 *
 * @param message the Spring Int message
 * @param channel the channel to send to
 *///from  ww  w  .  j a  va 2s . co m
private void sendMessage(final Message<?> message, final Object channel) {
    if (channel instanceof MessageChannel) {
        this.messagingTemplate.send((MessageChannel) channel, message);
    } else if (channel instanceof String) {
        this.messagingTemplate.send((String) channel, message);
    } else {
        throw new MessageDeliveryException(message,
                "a non-null reply channel value of type MessageChannel or String is required");
    }
}