## mrstub - stub interface to interact with the policy agent over Dmaap ##
The mrstub is intended for function tests to simulate a message router.
The mrstub exposes the read and write urls, used by the agent, as configured in consul.
In addition, request messages can be fed to the mrstub and the response messages can be read by polling.
### Control interface ###
The control interface can be used by any test script.
The following REST operations are available:
>Send a message to MR
This method puts a request message in the queue for the agent to pick up. The returned correlationId (auto generated by the mrstub) is used when polling for the reposone message of this particular request.
```URI and parameters (GET): /send-request?operation=&url=```
```response: (http 200) or 400 for parameter error or 500 for other errors```
>Receive a message response for MR for the included correlation id
The method is for polling of messages, returns immediately containing the received response (if any) for the supplied correlationId.
```URI and parameter, (GET): /receive-response?correlationId=```
```response: 200 or empty 204 or other errors 500```
>Metrics - counters
There are a number of counters that can be read to monitor the message processing. Do a http GET on any of the current counters and an integer value will be returned with http response code 200.
```/counter/requests_submitted``` - The total number of requests sent from the application
```/counter/requests_fetched``` - The total number of requests picked up by the agent
```/counter/responses_submitted``` - The total number of responses written by the agent
```/counter/responses_fetched``` - The total number of responses picked up by the application
```/counter/current_requests``` - The current number of requests waiting to be picked up by the agent
```/counter/current_responses``` - The current number of responses waiting to be picked up by the application
### Build and start ###
>Build image
```docker build -t mrstub .```
>Start the image
```docker run -it -p 3905:3905 mrstub```
The script ```mrstub-build-start.sh``` do the above two steps in one go. This starts the stub container in stand-alone mode for basic test.
If the mrstub should be executed manually with the agent, replace docker run with this command to connect to the docker network with the correct service name (--name shall be the same as configured in consul for the read and write streams).
```docker run -it -p 3905:3905 --network nonrtric-docker-net --name message-router mrstub```
### Basic test ###
Basic test is made with the script ```basic_test.sh``` which tests all the available urls with a subset of the possible operations. Use the script ```mrstub-build-start.sh``` to start the mrstub in a container first.