gopusu

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2016 License: BSD-3-Clause, MIT Imports: 7 Imported by: 1

README

PuSu Engine client for Golang

This is a client for the PuSu Engine written in Go. PuSu Engine is a Pub-Sub engine.

More information on the server repository at https://github.com/PuSuEngine/pusud.

Get it by running

go get github.com/PuSuEngine/gopusu

Usage

Examples are under tests/. Running the tests will require screen or multiple terminal windows.

One terminal window, running a listener;

cd tests
go run listener.go

Running basic test:

cd tests
go run basic.go

Running throughput:

cd tests
go run throughput.go

Short example how to connect to PuSu server:

package main

import "github.com/PuSuEngine/gopusu"

func main() {
    pc, _ := gopusu.NewPuSuClient("127.0.0.1", 55000)
    defer pc.Close()
    pc.Authorize("foo")
    pc.Subscribe("channel.1", listener)
    pc.Publish("channel.2", "message")
}

func listener(msg *gopusu.Publish) {
	// ...
}

License

Short version: MIT + New BSD.

Long version: Read the LICENSE.md -file.

Documentation

Overview

The Golang client for PuSu Engine. PuSu Engine is a (relatively) fast and scalable Pub-Sub message delivery system.

The Golang client is a simple (mostly) synchronous client that does little magic internally. For operations that the server acknowledges (Connect, Authorize, Subscribe) it waits for the appropriate event coming back from the server before continuing, to ensure you don't do stupid things and get unexpected results.

Example usage

package main

import (
    "fmt"
    "github.com/PuSuEngine/gopusu"
)

func main() {
    pc, _ := gopusu.NewPuSuClient("127.0.0.1", 55000)
    defer pc.Close()
    pc.Authorize("foo")
    pc.Subscribe("channel.1", listener)
    pc.Publish("channel.2", "message")
}

func listener(msg *gopusu.Publish) {
    fmt.Printf("Got message %s on channel %s\n", msg.Content, msg.Channel)
}

Index

Constants

This section is empty.

Variables

View Source
var ErrTimeoutExceeded = errors.New("Timeout exceeded when waiting for server to acknowledge message")

Timeout exceeded when waiting to acknowledge Authorize/Subscribe request

Functions

This section is empty.

Types

type Client

type Client struct {
	Timeout time.Duration
	// contains filtered or unexported fields
}

The PuSu client. Create one of these with NewClient(), and call the Authorize(), Subscribe() and Publish() methods to communicate with the PuSu network.

func NewClient

func NewClient(host string, port int) (pc *Client, err error)

Create a new PuSu client and connect to the given server

func (*Client) Authorize

func (pc *Client) Authorize(authorization string) error

Claim you have authorization to access some things. The server will determine what those things could be based on the configured authenticator and the data you give. Expect to get disconnected if this is invalid.

func (*Client) Close

func (pc *Client) Close()

Disconnect from the server

func (*Client) Connect

func (pc *Client) Connect() (err error)

Connect to the server

func (*Client) Publish

func (pc *Client) Publish(channel string, content string) error

Publish a message on the given channel

func (*Client) Subscribe

func (pc *Client) Subscribe(channel string, callback SubscribeCallback) error

Ask to subscribe for messages on the given channel. You MUST use the Authorize() method before this, even if server is configured to use the "None" authenticator. Expect to get disconnected if you lack the permissions.

type Publish

type Publish struct {
	Type    string `json:"type"`
	Channel string `json:"channel"`
	Content string `json:"content"`
}

Published message from the PuSu network. You get these to your callback if you subscribe to a channel.

type SubscribeCallback

type SubscribeCallback func(*Publish)

Callback to call with the published messages in a channel we're subscribed to.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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