Public test server for everyone!



We set up a publicly available server for everyone to use and play with! It is at public.pubsubsql.com:7777, give it a try!

To get you up and running quickly, you can use the examples available in this github repository. We’ll go through the code…

To set up a subscriber running in a matter of seconds, just connect, subscribe and wait for data to arrive:

    package main

    import (
        "fmt"
        "github.com/pubsubsql/client"
    )

    func main() {
        subscriber := new(pubsubsql.Client)
        address := "public.pubsubsql.com:7777"
        subscriber.Connect(address)

        subscriber.Execute("subscribe * from Stocks where MarketCap = 'MEGA CAP'")
        pubsubid := subscriber.PubSubId()

        fmt.Println("subscribed to Stocks pubsubid:", pubsubid)

        // timeout after a minute of no data
        timeout := 60000

        var action string
        for {
            subscriber.WaitForPubSub(timeout)
            action = subscriber.Action()
            fmt.Println("Action:", action)

            for {
                more, err := subscriber.NextRow()
                if err != nil {
                    fmt.Println(err.Error())
                    break
                } else if more == false {
                    break
                }

                for ordinal, column := range subscriber.Columns() {
                    fmt.Printf("%s:%s ", column, subscriber.ValueByOrdinal(ordinal))
                }
                fmt.Println("")

            }
        }
    }

And that’s it! Just build it and run it!

Running the subscriber on public server

In case you don’t see any data, no one is publishing it. In that case, you need to build the publisher as well. This publisher will randomly update the price of Google stock:

    package main

    import (
        "fmt"
        "math/rand"
        "time"

        "github.com/pubsubsql/client"
    )

    func CheckError(err error) {
        if err != nil {
            fmt.Println(err.Error())
        }
    }

    func main() {
        publisher := new(pubsubsql.Client)
        address := "public.pubsubsql.com:7777"
        publisher.Connect(address)

        publisher.Execute("key Stocks Ticker")
        publisher.Execute("tag Stocks MarketCap")
        publisher.Execute("insert into Stocks (Ticker, Price, MarketCap) values (GOOG, '1,2002d.22', 'MEGA CAP')")

        for {
            time.Sleep(300 * time.Millisecond)
            CheckError(publisher.Execute(fmt.Sprintf("update Stocks set Price='%f' where Ticker='GOOG'", 10000.0*rand.Float64())))
        }
    }

If you have any issues, just log an issue to github project or send us an email!






Share this post


comments powered by Disqus