Overview
We support Kafka and AMQP compatible brokers as messaging systems. You can use these messaging systems to send and receive messages between your services.
Data Model
Configuring a Message Broker
The first step to setting up messaging is configuring your message broker. This is done via the MessageBroker resource. This resource defines the type of broker you are using, and the connection details.
Configuring a Message Topic
Once you have configured your message broker, you can create a MessageTopic resource. This resource defines the topic you are using to send and receive messages.
Sending a Message
To send a message to a topic, you invoke the following Operation on the MessageTopic resource: $message-post
Example Request
POST /MessageTopic/${message-topic-id}/$message-post
{
"resourceType": "Parameters",
"parameter": [
{ "name": "input","resource": { "resourceType": "Patient" } }
]
}
Where Input can be any FHIR resource. The output of this operation is a code that represents the status of the message.
Tying a Subscription to a Message Topic
You can also configure a message topic to automatically send a message when a resource is created, updated, or deleted. This is done via the Subscription resource and the ClientApplication resource.
-
First create a client application as follows:
POST /ClientApplication
{
"name": "Message-Poster",
"secret": "my-secret",
"grantType": [
"basic_auth"
],
"resourceType": "ClientApplication",
"responseTypes": "token"
}Take note of the ClientApplication.id after creating it.
-
Tie an AccessPolicyV2 to your ClientApplication that allows it to post messages to the broker:
{
"name": "Admin",
"engine": "full-access",
"target": [
"link": {
"reference": "ClientApplication/${my-client-application-id}"
}
],
"resourceType": "AccessPolicyV2"
} -
We will now create Basic auth credentials header:
const header = btoa('${my-client-id}:${my-client-secret}')
-
Finally we create the Subscription resource
POST /Subscription
{
"reason": "Post message to broker",
"status": "active",
"channel": {
"type": "message",
"header": [
"Authorization: Basic ${output-from-step-3}"
],
"endpoint": "${my-domain}/w/${my-tenant-id}/api/v1/fhir/r4/MessageTopic/${my-topic-id}/$message-post"
},
"criteria": "Patient",
"resourceType": "Subscription"
}