Skip to content

PCS-Indonesia/pcspubsub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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