Skip to content
This repository was archived by the owner on Aug 13, 2020. It is now read-only.

JsonEnvelope Cookbook

allanmckenzie edited this page Sep 29, 2016 · 11 revisions

To create a full JsonEnvelope

import static uk.gov.justice.services.messaging.DefaultJsonEnvelope.envelopeFrom;
import static uk.gov.justice.services.messaging.JsonObjectMetadata.metadataWithRandomUUID;

    final UUID correlationId = randomUUID();
    final UUID sessionId = randomUUID();
    final UUID userId = randomUUID();
    final UUID streamId = randomUUID();
    final String commandName = "notification-added";

    final JsonObject payload = createObjectBuilder()
            .add("exampleField", "Example Value")
            .build();
    final JsonEnvelope command = envelopeFrom(
            metadataWithRandomUUID(commandName)
                    .withClientCorrelationId(correlationId.toString())
                    .withSessionId(sessionId.toString())
                    .withUserId(userId.toString())
                    .withStreamId(streamId)
                    .build(),
            payload
    );
Clone this wiki locally