io.fluxcapacitor.javaclient.publishing.DefaultResultGateway Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-client Show documentation
Show all versions of java-client Show documentation
Default Java client library for interfacing with Flux Capacitor.
package io.fluxcapacitor.javaclient.publishing;
import io.fluxcapacitor.common.api.Metadata;
import io.fluxcapacitor.common.api.SerializedMessage;
import io.fluxcapacitor.javaclient.common.serialization.MessageSerializer;
import io.fluxcapacitor.javaclient.publishing.client.GatewayClient;
import lombok.AllArgsConstructor;
@AllArgsConstructor
public class DefaultResultGateway implements ResultGateway {
private final GatewayClient client;
private final MessageSerializer serializer;
@Override
public void respond(Object payload, Metadata metadata, String target, int requestId) {
try {
SerializedMessage message = serializer.serialize(payload, metadata);
message.setTarget(target);
message.setRequestId(requestId);
client.send(message);
} catch (Exception e) {
throw new GatewayException(String.format("Failed to send response %s", payload), e);
}
}
}