Skip to content

Lightweight http adapter which allows to send nats requests to http for testing purposes

License

Notifications You must be signed in to change notification settings

PaulVasilenko/nats-http-adapter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NATS HTTP Adapter

That is currently in Alpha and lack of a everything you need, containing only what i need in current state

This software is made to make proxy API to send NATS messages through HTTP for testing purposes.

The main idea is to proxy HTTP requests to NATS to existing API testing tools (i.e. Postman) might be used to test code which receives data through NATS

Installation

First install command

GO111MODULE=on go get github.com/paulvasilenko/nats-http-adapter

After create config.yaml file with following structure

NATS:
  Endpoint: gnats://endpoint:4222
  RequestTimeout: 500ms # Default is 1s
HTTP:
  Port: 8085 # Default is 80

And run command

nats-http-adapter -c path/to/config.yaml

Usage

Requests should be sent to endpoint 127.0.0.1:8085/nats if you run it locally. Change address from localhost to yours if necessary.

Request

Example

{
    "subject":"ms_providers",
    "type":"req",
    "data": "any data"
}

List of params:

  • subject - is a subject to which message is sent
  • type - is a type of nats publish. Available types:
    • req - stands for request. Expects response, fails after timeout
    • pub - stands for publish. Would just publish message and then return 204 No Content
  • data - raw text of data. Might be JSON or whatever you like.

Response

OK

OK response is returned only for req message type. data contains and answer received through NATS.

If data is returned as JSON it would be encoded as JSON, otherwise as a raw string

{
    "data": "json object or string representation of data"
}

pub message type returns 204 No Content always.

Error

Error response is returned only in case of adapter internal error, not receiver error

400 Bad Request returned if some params are missing

TODO

  • Only human-readable raw text is available now, support of protobuf should be implemented
  • Implement other message types (RequestPublish, deliver etc)
  • Wrap it into Docker container

About

Lightweight http adapter which allows to send nats requests to http for testing purposes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages