All of NATS core features will be supported when communicating with Memphis, but without performing the below procedure, the Memphis platform will not be able to control and display the created objects, and therefore it is not recommended.
Memphis operates at the stream level. For a NATS subject to be visible and managed by Memphis, it must first be wrapped by a stream.
Follow the below instructions based on your Memphis deployment type:
Allowed characters for stream name. Any other character will not be accepted.
a-z/A-Z
0-9
_ -
Replacements in the client's code -
Redirect the servers parameter to Memphis broker hostname.
Change port 4222 to 6666
In Memphis GUI, create a client-type user based on the one you are (or not) using with NATS
Code Example (Before)
main.py
import asyncioimport natsasyncdefmain(): connection_opts ={"servers":"localhost:4222","allow_reconnect":True,"max_reconnect_attempts":10,"reconnect_time_wait":3,"connect_timeout":15,"user":"nats",# Optional in NATS. Mandatory in Memphis."password":"natspassword"# Optional in NATS. Mandatory in Memphis.} conn =await nats.connect(**connection_opts)await conn.publish("test", "hello world".encode())await conn.close()if__name__=="__main__": asyncio.run(main())
Code Example (After)
main.py
import asyncioimport natsasyncdefmain(): connection_opts ={"servers":"localhost:6666","allow_reconnect":True,"max_reconnect_attempts":10,"reconnect_time_wait":3,"connect_timeout":15,"user":"nats",# Optional in NATS. Mandatory in Memphis."password":"natspassword"# Optional in NATS. Mandatory in Memphis.} conn =await nats.connect(**connection_opts)await conn.publish("test", "hello world".encode())await conn.close()if__name__=="__main__": asyncio.run(main())
Important to know
Messages' producers' names will be displayed as "Unknown".
stream names in NATS are case sensitive, while in Memphis, they are lower-cased, so please consider using only lower-cased names.
In case a station has been created using Memphis GUI/SDK, and you want to produce messages to the same created station, you will have to send the messages into a subject called <stream_name>$<partition_number(starts from 1)>.final.
In case your station name contains a '.' sign replace it with '#' sign in the subject name level.
Example
Using Memphis NATS API compatibility to integrate Memphis with Argo