megaphone-client-golang

module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2019 License: GPL-3.0

README

Megaphone Golang client

GoDoc Go Report Card Build Status

Send events to Megaphone from Golang applications.

Getting Started

Install the package:

# Using Go get:
go get github.com/redbubble/megaphone-client-golang/megaphone

# Using govendor:
govendor fetch github.com/redbubble/megaphone-client-golang/megaphone@v1

Usage for Fluentd Client

In order to be as unobstrusive as possible, this client will append events to local files (e.g. ./work-updates.stream) unless:

  • the MEGAPHONE_FLUENT_HOST and MEGAPHONE_FLUENT_PORT environment variables are set.
  • or the Fluentd host and port values are passed as arguments to the client's constructor

That behaviour ensures that unless you want to send events to the Megaphone streams, you do not need to start Fluentd at all.

Publishing events
  1. Start Fluentd, the easiest way to do so is using a redbubble/megaphone-fluentd container

  2. Create your event and publish it:

// Configure a Megaphone client for your awesome service
client, err := megaphone.NewFluentdClient("my-awesome-service", "localhost", 24224)

// Create an event
topic := "work-updates"
subtopic := "work-metadata-updated"
schema := "https://github.com/redbubble/megaphone-event-type-registry/blob/master/streams/work-updates-schema-1.0.0.json"
partitionKey := "1357924680" # the Work ID in this case
payload := "{ url: \"https://www.redbubble.com/people/wytrab8/works/26039653-toadally-rad\" }"

// Publish your event
err := client.Publish(topic, subtopic, schema, partitionKey, payload)
if err != nil {
  // handle the error
}

Usage using Kinesis Publisher (synchronous)

This publisher writes to Kinesis directly, using an AWS Kinesis client.

Publishing events
  1. Create a new client

publisher, err := megaphone.NewKinesisSynchronousPublisher(kinesisclient.Config{
  Origin: "my-awesome-service",
  DeployEnv: "test",
  HostedOnAWS: true,
})
  1. Publish your event
topic := "work-updates"
subtopic := "work-metadata-updated"
schema := "https://github.com/redbubble/megaphone-event-type-registry/blob/master/streams/work-updates-schema-1.0.0.json"
partitionKey := "1357924680" # the Work ID in this case
payload := "{ url: \"https://www.redbubble.com/people/wytrab8/works/26039653-toadally-rad\" }"

err := publisher.Publish(topic, subtopic, schema, partitionKey, payload)
if err != nil {
  // handle the error
}

Credits

This Megaphone Golang client is maintained and funded by Redbubble.

License

megaphone
Copyright (C) 2017 Redbubble

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

Directories

Path Synopsis
Package megaphone provides a client for Megaphone, Redbubble's event broadcasting system for inter-service communication.
Package megaphone provides a client for Megaphone, Redbubble's event broadcasting system for inter-service communication.
logger
Package logger provides a logger that the Megaphone client can use to publish to a local file or to Megaphone via Fluentd.
Package logger provides a logger that the Megaphone client can use to publish to a local file or to Megaphone via Fluentd.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL