HTTP interface to AMPQ.
- It publishes an AMQP request message for each HTTP request received. Then it waits for the corresponding AMQP response message in order to answer to the original HTTP request.
- The topic of the message that it publishes comes from the method and the path of the HTTP request, replacing slashes (/) with dots (.).
- e.g.:
GET http://localhost:18080/net/test
→get.net.test
- e.g.:
- The topic of the response messages to close the connection is
queries.response
. These response messages must carry the same ID as the request they intend to close. - The default TTL for the published messages is 1000 ms. After that, the connection will be closed with a timeout if a response did not arrive.
- The exchange used by default is 'events'.
You need a Go runtime installed in your system which supports modules. A nice way to have multiple Go versions and switch easily between them is the g application.
A Makefile is available, so you only need to run:
make build
Make sure that you have built the binaries from the previous section, because the tests will run the echoservice
binary.
Load environment variables to set the BROKER_URI environment variable.
source dev/env_develop
Start a RabbitMQ service with default configuration (specified in /dev/env_develop
).
make start_dependencies
Run tests. They will only work if the RabbitMQ container is up.
make test
The Jenkins pipeline will generate two containers, which we can also build locally. One for compiling the app (http2amqp-builder), and the other to deploy its binary (http2amqp). This avoids the need of having Go installed in the host system. Take a look at the Dockerfile for more details.
make build_images
Once built, if we want to run the tests inside the builder image, we can do the following (remember to have the environment variables loaded and the RabbitMQ container up too):
docker run --rm -it --net=host aleasoluciones/http2amqp-builder:GIT_REV integration-tests
And to run http2amqp from inside the container:
docker run --rm -it --net=host -e BROKER_URI=amqp://guest:guest@localhost:5666/ aleasoluciones/http2amqp:GIT_REV
$ ./http2amqp -help
Usage of ./http2amqp:
-address string
HTTP listen IP address (default "0.0.0.0")
-brokeruri string
AMQP broker connection URI (default "amqp://guest:guest@localhost/")
-exchange string
AMQP broker exchange name (default "events")
-port string
HTTP listen port (default "18080")
-timeout int
AMQP broker queries timeout in milliseconds (default 1000)
-verbose
Verbose mode, enable logging
Make sure that the environment variables are loaded before executing each command. Also that you have a RabbitMQ container up and running with those parameters.
Start the htt2amqp server in a terminal.
./http2amqp -verbose
Start the echo service in another terminal. This will publish a response event each time a request event arrives, with the same ID and payload (ping pong).
./echoservice
Make a request with a payload. The echo service will answer back if running, otherwise it will timeout.
curl -X GET http://localhost:18080/net/test -d 'hello world'
You can specify the timeout (in milliseconds) as a query param.
curl -X GET http://localhost:18080/net/test?timeout=200 -d 'hello world'
- Test timeout parameter for each request.
- Implement delay parameter for echo server to allow tests timeouts.
- We compile in the Dockerfile with CGO_ENABLED=0 because in the scratch image there are not some C libraries it needs. So we compile the application with them in order to run it properly. See https://go.dev/blog/cgo for more info.