use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageRequest in project zeebe by camunda.
the class PublishMessageCommandImpl method send.
@Override
public ZeebeFuture<PublishMessageResponse> send() {
final PublishMessageRequest request = builder.build();
final RetriableClientFutureImpl<PublishMessageResponse, GatewayOuterClass.PublishMessageResponse> future = new RetriableClientFutureImpl<>(PublishMessageResponseImpl::new, retryPredicate, streamObserver -> send(request, streamObserver));
send(request, future);
return future;
}
use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageRequest in project zeebe by camunda.
the class PublishMessageTest method shouldMapRequestAndResponse.
@Test
public void shouldMapRequestAndResponse() {
// given
final PublishMessageStub stub = new PublishMessageStub();
stub.registerWith(brokerClient);
final String variables = JsonUtil.toJson(Collections.singletonMap("key", "value"));
final PublishMessageRequest request = PublishMessageRequest.newBuilder().setCorrelationKey("correlate").setName("message").setMessageId("unique").setTimeToLive(123).setVariables(variables).build();
// when
final PublishMessageResponse response = client.publishMessage(request);
// then
assertThat(response).isNotNull();
final BrokerPublishMessageRequest brokerRequest = brokerClient.getSingleBrokerRequest();
assertThat(brokerRequest.getIntent()).isEqualTo(MessageIntent.PUBLISH);
assertThat(brokerRequest.getValueType()).isEqualTo(ValueType.MESSAGE);
final MessageRecord brokerRequestValue = brokerRequest.getRequestWriter();
assertThat(bufferAsString(brokerRequestValue.getCorrelationKeyBuffer())).isEqualTo(request.getCorrelationKey());
assertThat(bufferAsString(brokerRequestValue.getNameBuffer())).isEqualTo(request.getName());
assertThat(bufferAsString(brokerRequestValue.getMessageIdBuffer())).isEqualTo(request.getMessageId());
assertThat(brokerRequestValue.getTimeToLive()).isEqualTo(request.getTimeToLive());
MsgPackUtil.assertEqualityExcluding(brokerRequestValue.getVariablesBuffer(), variables);
}
use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageRequest in project zeebe by camunda.
the class PublishMessageTest method shouldPublishMessage.
@Test
public void shouldPublishMessage() {
// given
final long messageKey = 123L;
gatewayService.onPublishMessageRequest(messageKey);
// when
final PublishMessageResponse response = client.newPublishMessageCommand().messageName("name").correlationKey("key").timeToLive(Duration.ofDays(1)).messageId("theId").send().join();
// then
final PublishMessageRequest request = gatewayService.getLastRequest();
assertThat(request.getName()).isEqualTo("name");
assertThat(request.getCorrelationKey()).isEqualTo("key");
assertThat(request.getMessageId()).isEqualTo("theId");
assertThat(request.getTimeToLive()).isEqualTo(Duration.ofDays(1).toMillis());
assertThat(response.getMessageKey()).isEqualTo(messageKey);
rule.verifyDefaultRequestTimeout();
}
use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageRequest in project zeebe by camunda.
the class PublishMessageTest method shouldPublishMessageWithStringVariables.
@Test
public void shouldPublishMessageWithStringVariables() {
// when
client.newPublishMessageCommand().messageName("name").correlationKey("key").variables("{\"foo\":\"bar\"}").send().join();
// then
final PublishMessageRequest request = gatewayService.getLastRequest();
assertThat(fromJsonAsMap(request.getVariables())).contains(entry("foo", "bar"));
}
use of io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageRequest in project zeebe by camunda.
the class PublishMessageTest method shouldPublishMessageWithObjectVariables.
@Test
public void shouldPublishMessageWithObjectVariables() {
// when
client.newPublishMessageCommand().messageName("name").correlationKey("key").variables(new Variables()).send().join();
// then
final PublishMessageRequest request = gatewayService.getLastRequest();
assertThat(fromJsonAsMap(request.getVariables())).contains(entry("foo", "bar"));
}
Aggregations