org.springframework.jms.listener.adapter

## Class JmsResponse<T>

- java.lang.Object
- - org.springframework.jms.listener.adapter.JmsResponse<T>

Type Parameters:
  `T` - the type of the response

    public class JmsResponse<T>
    extends Object

Return type of any JMS listener method used to indicate the actual response destination alongside the response itself. Typically used when said destination needs to be computed at runtime.

The example below sends a response with the content of the `result` argument to the `queueOut Queue`:

     package com.acme.foo;

     public class MyService {
         @JmsListener
         public JmsResponse process(String msg) {
             // process incoming message
             return JmsResponse.forQueue(result, "queueOut");
         }
     }

If the destination does not need to be computed at runtime, `@SendTo` is the recommended declarative approach.

Since:
  4.2
Author:
  Stephane Nicoll
See Also:
  `JmsListener`, `SendTo`

### Constructor Summary

Constructors
`protected` `JmsResponse(T response, Object destination)` Create a new `JmsResponse` instance.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static <T> JmsResponse<T>` `forDestination(T result, Destination destination)` Create a `JmsResponse` targeting the specified `Destination`.
`static <T> JmsResponse<T>` `forQueue(T result, String queueName)` Create a `JmsResponse` targeting the queue with the specified name.
`static <T> JmsResponse<T>` `forTopic(T result, String topicName)` Create a `JmsResponse` targeting the topic with the specified name.
`T` `getResponse()` Return the content of the response.
`Destination` `resolveDestination(DestinationResolver destinationResolver, Session session)` Resolve the `Destination` to use for this instance.
`String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### JmsResponse

    protected JmsResponse(T response,
                          Object destination)

Create a new `JmsResponse` instance.

Parameters:
  `response` - the content of the result
  `destination` - the destination

### Method Detail

#### getResponse

    public T getResponse()

Return the content of the response.

#### resolveDestination

    @Nullable
    public Destination resolveDestination(DestinationResolver destinationResolver,
                                                    Session session)
                                             throws JMSException

Resolve the `Destination` to use for this instance. The `DestinationResolver` and `Session` can be used to resolve a destination at runtime.

Parameters:
  `destinationResolver` - the destination resolver to use if necessary
  `session` - the session to use, if necessary
Returns:
  the `Destination` to use
Throws:
  `JMSException` - if the DestinationResolver failed to resolve the destination

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### forQueue

    public static <T> JmsResponse<T> forQueue(T result,
                                              String queueName)

Create a `JmsResponse` targeting the queue with the specified name.

#### forTopic

    public static <T> JmsResponse<T> forTopic(T result,
                                              String topicName)

Create a `JmsResponse` targeting the topic with the specified name.

#### forDestination

    public static <T> JmsResponse<T> forDestination(T result,
                                                    Destination destination)

Create a `JmsResponse` targeting the specified `Destination`.