Search in sources :

Example 1 with PublishMessageRequest

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;
}
Also used : PublishMessageResponse(io.camunda.zeebe.client.api.response.PublishMessageResponse) RetriableClientFutureImpl(io.camunda.zeebe.client.impl.RetriableClientFutureImpl) PublishMessageResponseImpl(io.camunda.zeebe.client.impl.response.PublishMessageResponseImpl) PublishMessageRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageRequest)

Example 2 with PublishMessageRequest

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);
}
Also used : BrokerPublishMessageRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerPublishMessageRequest) PublishMessageResponse(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageResponse) MessageRecord(io.camunda.zeebe.protocol.impl.record.value.message.MessageRecord) BufferUtil.bufferAsString(io.camunda.zeebe.util.buffer.BufferUtil.bufferAsString) PublishMessageRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageRequest) BrokerPublishMessageRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerPublishMessageRequest) GatewayTest(io.camunda.zeebe.gateway.api.util.GatewayTest) Test(org.junit.Test)

Example 3 with PublishMessageRequest

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();
}
Also used : PublishMessageResponse(io.camunda.zeebe.client.api.response.PublishMessageResponse) PublishMessageRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageRequest) ClientTest(io.camunda.zeebe.client.util.ClientTest) Test(org.junit.Test)

Example 4 with PublishMessageRequest

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"));
}
Also used : PublishMessageRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageRequest) ClientTest(io.camunda.zeebe.client.util.ClientTest) Test(org.junit.Test)

Example 5 with PublishMessageRequest

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"));
}
Also used : PublishMessageRequest(io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageRequest) ClientTest(io.camunda.zeebe.client.util.ClientTest) Test(org.junit.Test)

Aggregations

PublishMessageRequest (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageRequest)21 Test (org.junit.Test)18 ClientTest (io.camunda.zeebe.client.util.ClientTest)15 PublishMessageResponse (io.camunda.zeebe.client.api.response.PublishMessageResponse)6 RetriableClientFutureImpl (io.camunda.zeebe.client.impl.RetriableClientFutureImpl)3 PublishMessageResponseImpl (io.camunda.zeebe.client.impl.response.PublishMessageResponseImpl)3 GatewayTest (io.camunda.zeebe.gateway.api.util.GatewayTest)3 BrokerPublishMessageRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerPublishMessageRequest)3 PublishMessageResponse (io.camunda.zeebe.gateway.protocol.GatewayOuterClass.PublishMessageResponse)3 MessageRecord (io.camunda.zeebe.protocol.impl.record.value.message.MessageRecord)3 BufferUtil.bufferAsString (io.camunda.zeebe.util.buffer.BufferUtil.bufferAsString)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 HashMap (java.util.HashMap)3