Integrating with Golang Apps
In some cases, it can be useful to embed a RoadRunner server inside another GO program. This is often the case in microservice architectures where you may have a mandated GO framework for all the apps. In such cases it might not be possible to run a stock roadrunner instance, and the only choice is to run roadrunner inside the main app framework / program.
Here's an example of how to embed RoadRunner into a Go program with an HTTP handler:
Import RoadRunner library via go get
command into your Go project:
Create an RR instance
Here we use the default list of plugins. The same list of plugin you would get if you were to run rr serve
with a stock roadrunner binary.
You can, however, choose only the plugins you want and add your own private plugins as well:
Starting & Stopping Embedded Roadrunner
Once everything is ready, we can start the roadrunner instance:
rr.Serve()
will block until it returns an error or nil
if it was stopped gracefully.
To gracefully stop the server, simply call rr.Stop()
Last updated