npm install
docker-compose up
Before you start the server @gapi/cli
needs to be installed
npm i -g @gapi/cli
npm start
http://localhost:9000/graphiql
There is a mutation called sendMessage
mutation {
sendMessage(message: "my-message") {
message
}
}
The actual code which does the message sending in queue looks like this
@Type(AppType)
@Mutation({
message: {
type: new GraphQLNonNull(GraphQLString),
},
})
sendMessage(root, { message }): IAppType {
this.pubsub.publish('MY_CHANNEL', { message });
return { message };
}
subscription {
listenForChanges {
message
}
}
The actual code for creating this subscription looks like this
@Type(AppType)
@Subscribe(function(this: AppQueriesController) {
return this.pubsub.asyncIterator('MY_CHANNEL');
})
@Subscription()
listenForChanges(message: IAppType) {
return message;
}
So actually we are publishing messages to the queue they are send to RabbitMQ and every listener aka subscriber is using listenForChanges
subscription query to get the actual changes send by sendMessage
mutation.
We should see prompt for login so we can use our default credentials defined inside docker-compose
username: my-user
password: my-user-password
Notice that until you have a subscriber to a particular topic the connection with RabbitMQ is lazy and will not be established.
As long as listenForChanges
is subscribed using the Graphql Playground we should imidiately see that Exchanges, Queues and Connections are defined.
Note: in order for the changes to take effect server needs to be stopped and started again
config:
# Application configuration
app:
local:
API_PORT: 9000
NODE_ENV: development
GRAPHIQL_TOKEN: ''
AMQP_HOST: 142.10.0.5
AMQP_PORT: 5672
AMQP_USER: my-user
AMQP_PASS: my-user-password
RABBITMQ_ENABLED: true
If RABBITMQ_ENABLED
is commented out internal fake pubsub will be used especially good for development purposes in order to not spin up whole RabbitMQ server
This module is really awesome since it gives you a Flow Diagram for all the nodes that are created
The module can be installed using npm
npm install @gapi/voyager
Then import the module inside app.module.ts
imports
import { Module } from '@gapi/core';
import { VoyagerModule } from '@gapi/voyager';
@Module({
imports: [VoyagerModule.forRoot()],
})
export class AppModule {}
To access Voyager go to address http://localhost:9000/voyager
Njoy!