services

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2023 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PingPongServiceChan = "ping-pong-service"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type PingPongService

type PingPongService struct{}

PingPongService is a very simple service to demonstrate how request-response cycles are handled in Transport & Plank. this service has two requests named "ping-post" and "ping-get", the first accepts the payload and expects it to be of a POJO type (e.g. {"anything": "here"}), whereas the second expects the payload to be a pure string. a request made through the Event Bus API like bus.RequestOnce() will be routed to HandleServiceRequest() which will match the request's Request to the list of available service request types and return the response.

func NewPingPongService

func NewPingPongService() *PingPongService

func (*PingPongService) GetRESTBridgeConfig

func (ps *PingPongService) GetRESTBridgeConfig() []*service.RESTBridgeConfig

GetRESTBridgeConfig returns a list of REST bridge configurations that Plank will use to automatically register REST endpoints that map to the requests for this service. this means you can map any request types defined under HandleServiceRequest with any combination of URI, HTTP verb, path parameter, query parameter and request headers. as the service author you have full control over every aspect of the translation process which basically turns an incoming *http.Request into model.Request. See FabricRequestBuilder below to see it in action.

func (*PingPongService) HandleServiceRequest

func (ps *PingPongService) HandleServiceRequest(request *model.Request, core service.FabricServiceCore)

HandleServiceRequest routes the incoming request and based on the Request property of request, it invokes the appropriate handler logic defined and separated by a switch statement like the one shown below.

func (*PingPongService) Init

Init will fire when the service is being registered by the fabric, it passes a reference of the same core Passed through when implementing HandleServiceRequest

func (*PingPongService) OnServerShutdown

func (ps *PingPongService) OnServerShutdown()

OnServerShutdown is the opposite of OnServiceReady. it is called when the server enters graceful shutdown where all the running services need to complete before the server could shut down finally. this method does not need to return anything because the main server thread is going to shut down soon, but if there's any important teardown or cleanup that needs to be done, this is the right place to perform that.

func (*PingPongService) OnServiceReady

func (ps *PingPongService) OnServiceReady() chan bool

OnServiceReady contains logic that handles the service initialization that needs to be carried out before it is ready to accept user requests. Plank monitors and waits for service initialization to complete by trying to receive a boolean payload from a channel of boolean type. as a service developer you need to perform any and every init logic here and return a channel that would receive a payload once your service truly becomes ready to accept requests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL