localhost:9000in the browser, it should show you the Memphis UI.
memphis. These are the default credentials of the “root” user when you set up Memphis with Docker.
chatas the factory name. Enter
chatas the station name. Click “Next”.
chatas the application user name. Click “Create app user”. It should show you “memphis” as the connection token (password). This is the default.
chatabove. We are using
chatto keep things simple. Use names that are meaningful to your project. The Memphis UI permits you to manage factories, stations, and users. You can create more users with varying passwords/token. This ensures security.
npm install -g @nestjs/cli
fast-chatfor the project name. Run the following command:
nest new fast-chat -p npm
-pflag is use npm as package manager. Open the newly created
fast-chatproject in your favorite code editor.
host: The domain name or IP address where Memphis is found, e.g. localhost
username: The user that NestJS will act on their behalf, e.g. root
connectionToken: The password (token actually) of the above user.
fast-chatproject. Run the following command to install it.
npm install --save @nestjs/config
src/app.module.tsfile among other files when we created the project. This file contains the declaration of AppModule. Replace the contents of AppModule with the following:
isGlobalto true. Doing this will auto-import the ConfigModule in all other modules we wil create (which is what we want). In consequent files that need any values from the
.envfile, you will only access them from ConfigService (coming later on)
broker.module.tsfile inside a new
brokerfolder. Delete the contents of this new
broker.module.tsfile and paste the following:
broker.service.tsfile inside the
brokerfolder. Delete its contents and paste the following:
.proto) file for the services in FastChat.
srcfolder, name this new folder
chat-message. Create a new file inside this new folder. Name the new file
chat-message.proto. Paste the following into this
"proto3", (the latest version).
messagein protobuf refers to a custom type we create.
ChatMessagecontains an author (a string), the message’s text (string) and when the time the message was sent.
int64is a safe way of representing time as a timestamp.
src/chat-message/chat-message.proto above file is an example. To tell Nest about it, add it to the
nest-cli.jsonfile. This file is directly inside the
fast-chatproject folder. Include the following into the JSON file:
src/main.tsfile and paste the following:
chat-message.interface.tsfile inside the
chat-messagefolder. Paste the following inside.
chat-message.module.tsfile inside the
chat-messagefolder. Given that we will use Memphis broker in the services, import the BrokerModule into this newly generated ChatMessageModule. Delete the contents of the
chat-message.module.tsfile and paste the following:
chat-message.controller.tsfile inside the
chat-messagefolder. Replace the contents of this file with the following:
message.ack();tells Memphis that the “message” is acknowledged (so that it won’t send that “message” again).
chatMessages$ReplaySubject as an Observable.
src/app.module.tswith the following:
client.controller.tsinside a new
clientfolder. Replace the contents of this new file with the following:
allmethod of the AllMessagesService and prints every ChatMessage to the console. It also exposes a
/clientPOST endpoint to receive messages and send them to Memphis broker (through the
sendmethod of SendMessageService).
nest startto start the NestJS application.
localhost:3000/client. The body of the post request should reflect a valid ChatMessage like:
localhost:9000, you should notice the sent message (event). Check the NestJS logs and notice that it printed your ChatMessage. Send more POST requests and notice the more messages and logs.
.protofile. We also implemented both services with the same controller. These were because of simplicity.