This microservice runs on port 8009 and enables users to search message content using Elasticsearch. Searchservice depends on Elasticsearch and RabbitMQ.
SearchService expects messages on port 5672 for the RabbitMQ fanout exchange messages, posted in the JSON document format:
{
"_id": {
"$oid": "664752b07daf56ec5f3e6bca"
},
"from": "user123",
"to": "user321",
"message": "Hello!",
"date": "2024-05-17T12:50:56.992273584Z"
}
The Post Service in the example below posts messages in this format.
The endpoint /search allows searching across all messages for a user.
You can optionally include otherUserID to search within conversations between yourself and another user.
-
Endpoint:
/search -
Query Parameters:
text: The search query.otherUserID(optional): Specify another user's ID to search within conversations.
-
Example
-
to get all results of which the user is either sender or receiver of:
GET /search?text=example
or, to get all results within a conversation:
GET /search?text=example&otherUserID=123
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.10.4
container_name: elasticsearch-container
ports:
- 9200:9200
environment:
- discovery.type=single-node
- xpack.security.enabled=false
rabbitMQ:
image: 'rabbitmq:3-management'
container_name: QueueRabbitMQ
volumes:
- dbData:/var/lib/rabbitmq
ports:
- "15672:15672"
- "5672:5672"
environment:
- RABBITMQ_DEFAULT_VHOST=/
- RABBITMQ_FANOUT_EXCHANGE=fanoutExchange
app:
image: ghcr.io/chatgut/micropostservice:main
container_name: postService
restart: on-failure
depends_on:
- mongodb
- rabbitMQ
environment:
ROCKET_DATABASES: '{postservice={url="mongodb://dbMongoDB:27017"}}'
ROCKET_RABBIT_HOST: "amqp://QueueRabbitMQ:5672"
ports:
- "8000:8000"
mongodb:
image: 'mongo:latest'
container_name: dbMongoDB
volumes:
- dbData:/var/lib/mongodb
ports:
- "27017:27017"
searchservice:
image: mattan41/chatgut:v1.1
container_name: searchService
restart: on-failure
depends_on:
- rabbitMQ
- elasticsearch
ports:
- "8004:8004"
- Clone this repository.
- run with docker-compose up.