Skip to main content

FTL Client API

The samples provided use our FTL API to send messages. We will show an example of our API being used to send a message on a queue.

info

These snippets skip full production error handling and closing. Use best practices when creating applications.

Subscriber

We first connect to the FTL server and set up our message channel, event queue, and the subscriber on the quickstart queue destination:

realm, _ := ftl.Connect("http://localhost:8585", "", nil)
messageChannel := make(chan ftl.Message)
queue, _ := realm.NewQueue(nil, nil)
sub, _ := queue.SubscribeOnDest("Q:quickstart.queue", nil, messageChannel)

We then wait for the message on our message channel and print its contents upon obtaining it:

msg := <-messageChannel
fmt.Printf("received message: %s\n", msg.String())

Publisher

We first connect to the FTL server and make a new destination publisher:

realm, _ := ftl.Connect("http://localhost:8585", "", nil)
pub, _ := realm.NewDestPublisher("", nil)

Then, we create a new message and set its type and message content:

msg, _ := realm.NewMessage("")
content := make(map[string]interface{})
content["type"] = "hello"
content["message"] = "hello world earth"

Lastly, we attach the content to the message and send it on our quickstart queue destination:

msg.Marshal(&content)
pub.Send("Q:quickstart.queue", msg)