How To create a messaging based application

MICO supports two different communication types between microservices. The standard communication type is http. These connections use the service interfaces as described in How To manage an application. The second communication type is cloud events over Kafka.

Kafka enabled services

To use the provided Kafka broker a service hast to be marked as Kafka Enabled. Such a service does not need to specify an http interface to be deployable.

See How To add a service for details on how to add and edit a service.

Note

The UST-MICO Organization on GitHub has three example repositories containing Kafka enabled services that you can import directly.

Hint

For all Kafka enabled services the following environment variables will be set:

KAFKA_BOOTSTRAP_SERVERS
The URLs of the bootstrap servers
KAFKA_GROUP_ID
The group id to be used when subscribing to a Kafka topic
KAFKA_TOPIC_INPUT
The topic to receive messages from
KAFKA_TOPIC_OUTPUT
The topic to send messages to
KAFKA_TOPIC_INVALID_MESSAGE
The topic, to which invalid messages are forwarded
KAFKA_TOPIC_DEAD_LETTER
The topic, to which messages are forwarded that can’t/shouldn’t be delivered
KAFKA_TOPIC_TEST_MESSAGE_OUTPUT
The topic, to which test messages are forwarded at the end of a test

Input and output topic can be set by the user creating the application. The rest are set by the MICO system.

The Kafka-FaaS-Connector

The Kafka-FaaS-Connector is a special service that can be used to implement most of the Enterprise Integration Patters by Gregor Hohpe and Bobby Woolf The communication with Kafka and some of the cloud event attributes are managed by the Kafka-FaaS-Connector. Custom behaviour is implemented as a OpenFaaS-Function. The function can be managed with the supplied OpenFaaS dashboard that is linked to from the MICO dashboard. MICO will import the latest version of the Kafka-FaaS-Connector on startup automatically.

Creating messaging based networks

Note

For this tutorial the following assumptions are made:

The services UST-MICO/test_message_generator and UST-MICO/msg-validator have been imported from github.

Both services have to be edited to set the Kafka Enabled bit!

The service UST-MICO/msg-validator has an interface validator with Exposed Port Number 80, Target Port Number 8090 and type TCP.

The Application New Application includes both services.

Warning

The services have to be marked as Kafka enabled BEFORE being imported into the application to get all default settings for Kafka enabled services!

The starting configuration should look like this:

../_images/new-messaging-app.png

To link a Kafka enabled service with Kafka topic hover over the service and drag one of the appearing link handles.

The dragged edge can be dropped in the empty space to create a new topic.

In the add topic you can specify the topic and the role. The topic can either be used as a input to the service or as an output from the service. A service can only have one input and one output topic in the grapheditor.

../_images/add-topic-dialog.png

After confirming the dialog the topic appears in the grapheditor. If a topic is already in the grapheditor services can also be linked directly to the topics by dragging an edge from the topic to the service or from the service to the topic. The direction of the arrow symbolises the message flow.

../_images/messaging-app-first-topic.png

Add the topic as input topic to the UST-MICO/msg-validator service. This is a minimal configuration for a messaging based application.

../_images/messaging-app-small.png

To remove a link drage the link from the link handle near the link target on the link.

Drop the link on empty space to delete it.

To add a Kafka-FaaS-Connector to the application simply drag a edge from a topic and drop it over empty space. The Kafka-FaaS-Connector may take a few seconds to appear.

../_images/add-kafka-faas-connector.png

Dragg a edge from the Kafka-FaaS-Connector to connect it with a new topic.

../_images/messaging-app-second-topic.png
../_images/messaging-app-big.png

To change the FaaS function of the Kafka-FaaS-Connector click on the title of the Kafka-FaaS-Connector node to open the dialog.

../_images/update-faas-function-dialog.png

The title will change to the set FaaS function.

../_images/updated-faas-function.png