Class PublisherResponseType<R>

java.lang.Object
org.axonframework.messaging.responsetypes.AbstractResponseType<org.reactivestreams.Publisher<R>>
org.axonframework.messaging.responsetypes.PublisherResponseType<R>
Type Parameters:
R - The response type which will be matched against and converted to
All Implemented Interfaces:
Serializable, ResponseType<org.reactivestreams.Publisher<R>>

public class PublisherResponseType<R> extends AbstractResponseType<org.reactivestreams.Publisher<R>>
A ResponseType implementation that will match with query handlers that return a Publisher stream of the expected response type. If matching succeeds, the ResponseType.convert(Object) function will be called, which will cast the query handler it's response to R.
Since:
4.6.0
Author:
Stefan Dragisic, Milan Savic
See Also:
  • Field Details

  • Constructor Details

    • PublisherResponseType

      public PublisherResponseType(Class<?> expectedResponseType)
      Instantiate a PublisherResponseType with the given expectedResponseType as the type to be matched against and to which the query response should be converted to.
      Parameters:
      expectedResponseType - the response type which is expected to be matched against and returned
  • Method Details

    • matches

      public boolean matches(Type responseType)
      Match the query handler its response Type with this implementation its responseType R. Will return true if the expected type is assignable to the response type, taking generic types into account.
      Parameters:
      responseType - the response Type of the query handler which is matched against
      Returns:
      true if the response type is assignable to the expected type, taking generic types into account
    • matchRank

      public Integer matchRank(Type responseType)
      Description copied from interface: ResponseType
      Defines the match and its priority. The greater the value above 0, the better the match. This is particularly useful for MultipleInstancesResponseTypes when there are matches on a both multiple and single instance types. Lists should be given priority for handling.

      Parameters:
      responseType - the response Type of the query handler which is matched against
      Returns:
      ResponseType.NO_MATCH if there is no match, greater than 0 if there is a match. Highest match should win when choosing a query handler.
    • responseMessagePayloadType

      public Class responseMessagePayloadType()
      Description copied from interface: ResponseType
      Returns a Class representing the type of the payload to be contained in the response message.
      Returns:
      a Class representing the type of the payload to be contained in the response message
    • convert

      public org.reactivestreams.Publisher<R> convert(Object queryResponse)
      Description copied from interface: ResponseType
      Converts the given response of type Object into the type R of this ResponseType instance. Should only be called if ResponseType.matches(Type) returns true. It is unspecified what this function does if the ResponseType.matches(Type) returned false.
      Parameters:
      queryResponse - the Object to convert into R
      Returns:
      a response of type R
    • convertExceptional

      public Optional<org.reactivestreams.Publisher<R>> convertExceptional(Throwable e)
      Description copied from interface: ResponseType
      Converts the given Throwable into the type R of this ResponseType instance. Used when an error is represented as the message payload. The Optional is not empty when an error is represented as the message payload.
      Returns:
      a Optional response of type R
    • forSerialization

      public ResponseType<?> forSerialization()
      Description copied from interface: ResponseType
      Returns the ResponseType instance that should be used when serializing responses. This method has a default implementation that returns this. Implementations that describe a Response Type that is not suited for serialization, should return an alternative that is suitable, and ensure the ResponseType.convert(Object) is capable of converting that type of response to the request type in this instance.
      Returns:
      a ResponseType instance describing a type suitable for serialization