Skip to content

PubSub

In the world of microservice architecture, the event driven approach is indistinguishable and zero framework has built-in support for the accessing the message queue systems.

At times the app we develop has to rely on external service signal through API call and through events and let us decide the state of the data/action.

Alike, other built-in solutions, the PubSub clients will be automatically added to container once the needed service configurations available.

zero app tries to connect, captures the ping status and attaches to the app life-time, otherwise app explicitly calls the PubSub is disabled.

zig
ctx.KF.publish(ctx, "topic", "message-key", "payload"); #publishes message to a topic on the subscribed client

app.addKafkaSubscription("topic", subscriberHandler); #listens for upcoming event and injects into subscriber handler for further actions.
zig
ctx.MQ.publish("topic"); #publishes message to a topic on the subscribed client

app.addSubscription("topic", subscriber-handler); #listens for upcoming event and injects into subscriber handler for further actions.

Support

zero framework supports following brokers to publish and subscriber to.

Message BrokerSupport
Kafka
MQTT

Configurations

This list of configurations help the developer to prefer either Kafka or MQTT pubsub per instance.

kafka configRemarksDefault* / OthersRequired
PUBSUB_BACKENDChoose kafka or mqtt as pubsub mqNone (KAFKA / MQTT)Yes
PUBSUB_BROKERSet the addresses of the Kafka clusterlocalhost:9092 [one or multiple host address]Yes
PUBSUB_OFFSETAllow the subscription to begin fromNoneNo
CONSUMER_IDUnique identifier of the subscribing groupNoneNo
KAFKA_BATCH_SIZENumber of messages added in one messageSet100*No
KAFKA_BATCH_BYTESThe overall size of the messageSet that includes one or more message1048576*No
KAFKA_BATCH_TIMEOUTMessageSet flush timeout1000*No
KAFKA_SECURITY_PROTOCOLProtocol used to communicate with kafka clusterplaintext*,ssl,sasl_plaintext, sasl_sslNo
KAFKA_SASL_MECHANISMSASL Authentication mechanismplain*No
KAFKA_SASL_USERNAMESASL Authentication usernameApplicable only with sasl plain modeNo
KAFKA_SASL_PASSWORDSASL Authentication passwordApplicable only with sasl plain modeNo
KAFKA_TLS_CERT_FILEPath to client's public key (PEM) used for authentication.NoneNo
KAFKA_TLS_KEY_FILEPath to client's private key (PEM) used for authentication.NoneNo
KAFKA_TLS_CA_CERT_FILEPath to client's CA cert (PEM) used for authentication.NoneNo
KAFKA_TLS_INSECURE_SKIP_VERIFYSkip client certificate verificationstrue*, falseNo
MQTT configRemarksDefault* / OthersRequired
MQTT_PROTOCOLProtocol used to communicate with MQTT servertcp*Yes
MQTT_HOSTIP Address of the MQTT ServerNoneYes
MQTT_PORTPort of the MQTT ServerNoneYes
MQTT_CLIENT_ID_SUFFIXClient ID name for the debug messagesNoneNo