Class Subscriptions

java.lang.Object
com.commercetools.docs.meta.Subscriptions

public final class Subscriptions extends Object
Table of content

Subscriptions

Delivery Payloads

The SDK provides the JsonUtils class which can be used to deserialize the delivery payload sent by a subscription. Using the DeliveryPayload class it will deserialize it correctly to a MessageDeliveryPayload, ResourceCreatedDeliveryPayload, ResourceUpdatedDeliveryPayload, or ResourceDeletedDeliveryPayload

DeliveryPayload delivery = JsonUtils.fromJsonString(stringFromResource("messagedeliverypayload.json"),
    DeliveryPayload.class);
assertThat(delivery).isInstanceOf(DeliveryPayload.class);
assertThat(delivery).isInstanceOf(MessageDeliveryPayload.class);

See the test code.

Message Payloads

The MessageDeliveryPayload include a helper method to cast to the inner message delivery and return the wrapped message.

DeliveryPayload delivery = JsonUtils.fromJsonString(stringFromResource("messagedeliverypayload.json"),
    DeliveryPayload.class);

assertThat(delivery).isInstanceOf(MessageDeliveryPayload.class);
MessageDeliveryPayload messageDelivery = (MessageDeliveryPayload) delivery;

assertThat(messageDelivery.getMessagePayload()).isInstanceOf(CustomerLastNameSetMessagePayload.class);

assertThat(messageDelivery.getMessagePayload().as(CustomerLastNameSetMessagePayload.class))
        .isInstanceOf(CustomerLastNameSetMessagePayload.class);

assertThat(messageDelivery.hasCompleteMessage()).isTrue();

assertThatThrownBy(() -> messageDelivery.getMessagePayload().as(CustomerFirstNameSetMessagePayload.class))
        .isInstanceOf(IllegalArgumentException.class);

See the test code.

Change Payloads

DeliveryPayload delivery = JsonUtils.fromJsonString(stringFromResource("changedeliverypayload.json"),
    DeliveryPayload.class);

assertThat(delivery).isInstanceOf(ResourceCreatedDeliveryPayload.class);

See the test code.