Cookie Cutter

Cookie Cutter

  • Introduction
  • API
  • Help

›Modules

Introduction

  • Getting Started
  • Inputs
  • Message Handling
  • Outputs
  • Versioning and Contribution Guide

Components

  • Dispatch Context
  • State
  • Metrics
  • Tracing
  • Logging
  • Validation
  • Encoding
  • Config
  • Testing

Modules

  • Kafka
  • Azure
  • AMQP
  • gRPC
  • ValidateJS
  • MSSQL
  • Timer
  • StatsD
  • Protobuf
  • Prometheus
  • Redis
  • S3
  • Google PubSub

Google PubSub

pubSubSource

The pubSubSource function creates a new input source that receives messages from Google PubSub. The example below subscribes to the subscription subscription-name-1 and receives JSON encoded messages sent to that subscription.

Application.create()
    .input()
        .add(pubSubSource({
            projectId: "project-name-1",
            clientEmail: "myEmail@myserver.com",
            privateKey: "myPrivateKey",
            encoder: new JsonMessageEncoder(),
            subscriptionName: "subscription-name-1"
        }))
        .done()
    // ...
    .run();

Configuration

The available configuration options are

NameDescription
projectIdproject ID where subscription is present
clientEmailserivce account email ID that is authorized to access project resources
privateKeyprivate key used to authenticate access
encoderdefines how the raw data received from Kafka should be converted into message objects
subscriptionNamename of subscription to subscribe to in order to receive messages
maxMsgBatchSizethe max number of unacknowledged messages that client can have at a time, default value is 20
preprocessoroptional preprocessing function that allows for manipulation of the incoming message before decoding the message's payload. This can for instance be used for messages that are enveloped in some way

Metadata

NameDescription
EventSourcedMetadata.EventTypethe event that originally generated the message
EventSourcedMetadata.Timestampthe date/time when the topic originally received the message

Metrics

NameDescriptionTypeTags
cookie_cutter.pubsub_source.msg_receivedincreases the number of messages received from subscriptionincrementsubscription_name, event_type, result[1]

pubSubSink

The pubSubSink function creates an output sink that handles messages needed to be published to topic.

Application.create()
    .output()
        .published(pubSubSink({
            projectId: "prject-name-1",
            clientEmail: "myEmail@myserver.com",
            privateKey: "myPrivateKey",
            encoder: new JsonMessageEncoder()
        }))
        .done()
    // ...
    .run();

Configuration

The available configuration options are

NameDescription
projectIdproject ID where subscription is present
clientEmailserivce account email ID that is authorized to access project resources
privateKeyprivate key used to authenticate access
encoderdefines how the raw data received from Kafka should be converted into message objects
defaultTopicpublish to this topic when the message has no topic explicitly mentioned
maximumBatchSizethe number of messages handled per batch, default is 1000
maximumBatchWaitTimemaximum time in ms to hold a batch until being published to a topic , default is 100ms
maxPayloadSizemaximum size of batch in bytes, default is 5242880 bytes

Publishing to PubSub

Application.create()
    .dispatch({
        onSomeInputMessage(msg: ISomeInputMessage, ctx: IDispatchContext) {
            // publish a message to the default topic
            ctx.publish(Output, {
                field: "value",
            });

            // publish a message to a different topic
            ctx.publish(Output, {
                field: "value",
                metadata: { PubSubMetadata.Topic: "my-topic" },
            }, );
        }
    })
    .output()
        .published(pubSubSink({
            projectId: "prject-name-1",
            clientEmail: "myEmail@myserver.com",
            privateKey: "myPrivateKey",
            encoder: new JsonMessageEncoder()
        }))
        .done()
    // ...
    .run();

Metatdata

NameDescription
PubSubMetadata.Topicthe name of topic to publish

Metrics

NameDescriptionTypeTags
cookie_cutter.pubsub_sink.msg_publishedincreases the number of messages publishedincrementtopic, event_typ, result[1]

  1. result - Consists of the following

    NameDescription
    PubSubMetricResults. Successsuccessfully pusblished/read message from topic/subscription
    PubSubMetricResults.Errorerror while publishing/reading message from topic/subscription
    ↩ ↩
← S3
  • pubSubSource
    • Configuration
    • Metadata
    • Metrics
  • pubSubSink
    • Configuration
    • Publishing to PubSub
    • Metatdata
    • Metrics
Cookie Cutter
Docs
IntroductionKafka
More
Blog
Copyright © 2023 Walmart Inc.