HTTP
The HTTP subscriber listens to HTTP requests (for example - webhooks) and outputs them as messages. You can then post them to any Publisher. Here is an example with sending HTTP messages to Kafka .
The HTTP publisher sends HTTP requests as specified in its configuration. Here is an example with transforming Kafka messages into HTTP webhook requests .
Installation
Characteristics
Feature | Implements | Note |
---|---|---|
ConsumerGroups | no | |
ExactlyOnceDelivery | yes | |
GuaranteedOrder | yes | |
Persistent | no |
Subscriber configuration
Subscriber configuration is done via the config struct passed to the constructor:
Full source: github.com/ThreeDotsLabs/watermill-http/pkg/http/subscriber.go
You can use the Router
config option to SubscriberConfig
to pass your own chi.Router
(see chi
).
This may be helpful if you’d like to add your own HTTP handlers (e.g. a health check endpoint).
Publisher configuration
Publisher configuration is done via the config struct passed to the constructor:
Full source: github.com/ThreeDotsLabs/watermill-http/pkg/http/publisher.go
How the message topic and body translate into the URL, method, headers, and payload of the HTTP request is highly configurable through the use of MarshalMessageFunc
.
Use the provided DefaultMarshalMessageFunc
to send POST requests to a specific url:
Full source: github.com/ThreeDotsLabs/watermill-http/pkg/http/publisher.go
You can pass your own http.Client
to execute the requests or use Golang’s default client.
Running
To run HTTP subscriber you need to run StartHTTPServer()
. It needs to be run after Subscribe()
.
When using with the router, you should wait for the router to start.
Subscribing
Full source: github.com/ThreeDotsLabs/watermill-http/pkg/http/subscriber.go
Custom HTTP status codes
To specify a custom HTTP status code, which will returned as response, you can use following call during message handling: