Skip to content

Event Store - Lib, for use by team inhouse.

Notifications You must be signed in to change notification settings

Just4Ease/bifrost

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bifrost

How to use

package main

import (
 "github.com/roava/bifrost"
 "github.com/roava/bifrost/pulse"
 "log"
 "time"
)

func main() {
	
    var topic = "test-topic" // for random topic name.
    var store, _ = pulse.Init(bifrost.Options{
        ServiceName: "test-event-store",
	    Address: "pulsar://localhost:6650",
    })
	
	if err := store.Publish(topic, []byte("Hello World!")); err != nil {
		log.Fatalf("Could not publish message to %s", topic)
	}

	timer := time.AfterFunc(3*time.Second, func() {
		if err := store.Subscribe(topic, func(event bifrost.Event) {
			data := event.Data()

			eventTopic := event.Topic()

			if topic != eventTopic {
				log.Fatalf("Event topic is not the same as subscription topic. Why?: Expected %s, instead got: %s \n", topic, eventTopic)
				return
			}

			log.Printf("Received data: %s on topic: %s \n", string(data), eventTopic)
			event.Ack() // Acknowledge event.
			return
		}); err != nil {
			log.Fatalf("Failed to subscribe to topic: %s, with the following error: %v \n", topic, err)
			return
		}
	})

	defer timer.Stop()

}
# For tests

$ make test 

About

Event Store - Lib, for use by team inhouse.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published