Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorListener ¶ added in v0.1.4
type ErrorListener func(route metadata.EndpointRoute, err error)
ErrorListener defines a custom callback that you can use to listen for any error generated by an async event gateway invocation failure.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway encapsulates the logic to invoke service operations based on event sourcing. You should not create one of these yourself - use the NewGateway() constructor instead.
func NewGateway ¶
func NewGateway(options ...GatewayOption) *Gateway
NewGateway creates an event-sourced gateway that executes service methods based on event subscriptions. By default, events are sourced using local.Broker(). This means that events will only be available to services running in the services.Server that this gateway is added to. You can provide a broker to a different event source like NATS JetStream using the WithBroker() option.
func (*Gateway) Listen ¶
Listen causes the gateway to start subscribing/listening for events from the broker. This will block until we're told to stop by calling Shutdown().
func (*Gateway) Middleware ¶
func (gw *Gateway) Middleware() services.MiddlewareFuncs
Middleware returns the middleware functions that ALL server routes should include in order to make sure that this gateway actually works. For instance, one of the middleware functions publishes the service operation's success/failure to the event source/stream. This happens regardless of whether the operation was invoked through the API gateway or the event one. Basically, these are agnostic of the gateway type and will be added to ALL gateway routes, not just the event gateway.
func (*Gateway) Register ¶
func (gw *Gateway) Register(endpoint services.Endpoint, endpointRoute services.EndpointRoute)
Register adds the given service endpoint to the routing rules for this gateway. You will not invoke this yourself! The services.Server will utilize this as necessary.
func (*Gateway) Shutdown ¶
Shutdown gracefully stops the event gateway. It will allow all of the in-progress requests to finish up before doing so. You can provide a deadline to the context parameter to limit how much time you're willing to give them before shutting down anyway.
func (*Gateway) Type ¶
func (gw *Gateway) Type() services.GatewayType
Type returns "EVENTS" to indicate the tagging value for this gateway.
type GatewayOption ¶
type GatewayOption func(gw *Gateway)
GatewayOption defines a functional parameter that you can use to set up an event gateway.
func WithBroker ¶
func WithBroker(broker eventsource.Broker) GatewayOption
WithBroker defines the broker that the gateway will use to publish and listen for events. By default, the gateway will use a local broker that can only broadcast events to other services running inside the same services.Server instance.
func WithEncoding ¶
func WithEncoding(encoder codec.Encoder, decoder codec.Decoder) GatewayOption
WithEncoding allows you to customize how to marshal events to/from the broker. By default, the gateway will use standard library JSON encoding.
func WithErrorListener ¶ added in v0.1.4
func WithErrorListener(listener ErrorListener) GatewayOption
WithErrorListener sets a custom callback function that is invoked any time we encounter an error publishing an event, receiving an event, or executing a service handler. These are all invoked asynchronously, so this is the only way you can perform any custom error handling in those cases.
This is fired IN ADDITION to any "On Service.Method:Error" routes you've set up. It's a way for you to provide some general purpose recovery/logging/whatever on every failed async call.