Search in sources :

Example 1 with Builder

use of io.scalecube.transport.Message.Builder in project scalecube by scalecube.

the class Messages method asResponse.

/**
 * utility method to build service response message.
 *
 * @param data to be use for the response.
 * @param correlationId of a the given request.
 * @param memberId that created the response.
 * @return response message or response error message in case data is exception.
 */
public static Message asResponse(Object data, String correlationId, String memberId) {
    Builder builder = Message.builder().correlationId(correlationId).header("memberId", memberId);
    if (data instanceof Message) {
        Message msg = (Message) data;
        builder = builder.data(msg.data());
    } else {
        builder = builder.data(data);
        if (data instanceof Throwable) {
            builder = builder.header(ServiceHeaders.EXCEPTION, "");
        }
    }
    return builder.build();
}
Also used : Message(io.scalecube.transport.Message) Builder(io.scalecube.transport.Message.Builder)

Aggregations

Message (io.scalecube.transport.Message)1 Builder (io.scalecube.transport.Message.Builder)1