Skip to content

Latest commit

 

History

History
83 lines (65 loc) · 1.7 KB

readme.md

File metadata and controls

83 lines (65 loc) · 1.7 KB

PCS PubSubClient

Go Reference Go Report Card License

Overview

Internal Use of PCS Pub/Sub service.
Only for PCS Applications.

Installation

Use go get to install the package:

go get github.com/PCS-Indonesia/pcspubsub/pubsubclient

Command Message

{
    "command" : "insert|update|delete|notify",
    "payload" : <content>,
    "id"      : <id>,
    "detail"  : <additional data>
}

Examples

Listen to subscription

package main

import (
    "github.com/PCS-Indonesia/pcspubsub/pubsubclient"
)

func main() {
    pubsubclient.NewPubSubClient("project-id","your-credentials.json")
    pubsubclient.ReceiveMessages("subscription-name", func() {
        // Do something
    })
}

Publish to topic

package main

import (
    "github.com/PCS-Indonesia/pcspubsub/pubsubclient"
)

func main() {
    pubsubclient.NewPubSubClient("project-id","your-credentials.json")
    var message pubsubclient.CommandMessage
    message.Command = "command"
    message.Payload = "your json body"
    message.ID      = "id"
    message.Deatail = "detail"
    err := pubsubclient.PublishMessage("topic-name", message)
    if err != nil {
        // Error Handling
    }
}

Test sample

  • Copy credential file to root directory
  • Copy .env.example as .env and fill it
  • Run pub with
go run sample.go pub
  • Run sub with
go run sample.go sub