Skip to content

Commit

Permalink
replace local subscription code with github.com/sfomuseum/go-pubsub/s…
Browse files Browse the repository at this point in the history
…ubscriber
  • Loading branch information
thisisaaronland committed May 27, 2021
1 parent 42487d2 commit c6f9d62
Show file tree
Hide file tree
Showing 17 changed files with 592 additions and 205 deletions.
39 changes: 4 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Documentation is incomplete still.
```
import (
"context"
"github.com/sfomuseum/go-pubsub/subscriber"
"github.com/whosonfirst/go-pubssed/broker"
"github.com/whosonfirst/go-pubssed/subscription"
"net/http"
)
ctx := context.Background()
sub, _ := subscription.NewSubscription(ctx, "redis://?host=localhost&port=6379&channel=pubssed")
sub, _ := subscriber.NewSubscriber(ctx, "redis://?host=localhost&port=6379&channel=pubssed")
brkr, _ := broker.NewBroker()
brkr.Start(ctx, sub)
Expand Down Expand Up @@ -124,41 +124,10 @@ Usage of ./bin/pubssed-server:

An actuall living breathing server that will listen to (and relay) a PubSub channel and that an SSE client can connect to and receive messages.

## Docker

Yes. See the included [Dockerfile](Dockerfile) for details.

```
$> docker build -t go-pubssed .
...time passes
$> docker run go-pubssed /usr/bin/pubssed-server -h
Usage of /usr/bin/pubssed-server:
-redis-channel string
Redis channel (default "pubssed")
-redis-host string
Redis host (default "localhost")
-redis-port int
Redis port (default 6379)
-sse-endpoint string
SSE endpoint (default "/sse")
-sse-host string
SSE host (default "localhost")
-sse-port int
SSE port (default 8080)
```

For example:

```
$> docker run -p 6161:8080 go-pubssed /usr/bin/pubssed-server
2019/06/19 16:45:13 Listening on localhost:8080
```

By default `go-pubssed` expects to find a Redis channel to listen to on `localhost:6379`. The Dockerfile as it is written does not install Redis so it is up to you to specify an alternate Redis endpoint, somewhere outside of the `go-pubssed` Docker container.

## See also

* https://github.com/sfomuseum/go-pubsub

* https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
* https://github.com/go-redis/redis
* https://github.com/whosonfirst/go-webhookd
Expand Down
10 changes: 5 additions & 5 deletions broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package broker
import (
"context"
"fmt"
"github.com/whosonfirst/go-pubssed/subscription"
"github.com/sfomuseum/go-pubsub/subscriber"
"log"
"net/http"
)
Expand All @@ -27,10 +27,10 @@ func NewBroker() (*Broker, error) {
return &b, nil
}

func (b *Broker) Start(ctx context.Context, sub subscription.Subscription) error {

// set up the SSE monitor
func (b *Broker) Start(ctx context.Context, sub subscriber.Subscriber) error {

// set up the SSE monitor

go func() {

for {
Expand Down Expand Up @@ -69,7 +69,7 @@ func (b *Broker) Start(ctx context.Context, sub subscription.Subscription) error

// something something error handling...

sub.Start(ctx, b.messages)
sub.Listen(ctx, b.messages)
}()

return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/pubssed-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"flag"
"fmt"
"github.com/whosonfirst/go-pubssed/broker"
"github.com/whosonfirst/go-pubssed/subscription"
"github.com/sfomuseum/go-pubsub/subscriber"
"log"
"net/http"
"os"
Expand All @@ -29,7 +29,7 @@ func main() {

ctx := context.Background()

sub, err := subscription.NewSubscription(ctx, *subscription_uri)
sub, err := subscriber.NewSubscriber(ctx, *subscription_uri)

if err != nil {
log.Fatalf("Failed to create subscription for '%s', %v", *subscription_uri, err)
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/whosonfirst/go-pubssed
go 1.16

require (
github.com/aaronland/go-roster v0.0.2
github.com/go-redis/redis/v8 v8.8.3
github.com/aaronland/go-roster v0.0.2 // indirect
github.com/go-redis/redis/v8 v8.9.0
github.com/sfomuseum/go-pubsub v0.0.1
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGK
github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-redis/redis/v8 v8.8.3 h1:BefJyU89cTF25I00D5N9pJdWB1d1RBj8d7MBf71M7uQ=
github.com/go-redis/redis/v8 v8.8.3/go.mod h1:ik7vb7+gm8Izylxu6kf6wG26/t2VljgCfSQ1DM4O1uU=
github.com/go-redis/redis/v8 v8.9.0 h1:FTTbB7WqlXfVNdVv0SsxA+oVi0bAwit6bMe3IUucq2o=
github.com/go-redis/redis/v8 v8.9.0/go.mod h1:ik7vb7+gm8Izylxu6kf6wG26/t2VljgCfSQ1DM4O1uU=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
Expand All @@ -40,6 +42,8 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sfomuseum/go-pubsub v0.0.1 h1:F6geGCT6x85CizceIYziqSHkiz4EDt6nbHGaO8sqfis=
github.com/sfomuseum/go-pubsub v0.0.1/go.mod h1:9TaDs1QOcxOOdeA96B+Ld7Uj4+by6LEkeMyisqD8YuE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
37 changes: 0 additions & 37 deletions subscription/channel.go

This file was deleted.

5 changes: 5 additions & 0 deletions vendor/github.com/go-redis/redis/v8/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions vendor/github.com/go-redis/redis/v8/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c6f9d62

Please sign in to comment.