Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6928 documentation of mp reactive messaging stream operators 3-9 #7250

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 23 additions & 33 deletions modules/ROOT/pages/liberty-kafka-connector.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,14 @@ The following sections describe how to intergrate MicroProfile Reactive Messagin
[#configuration]
== Configure the Liberty-Kafka connector

The `liberty-kafka` connector enables applications to send and receive messages from an Apache Kafka broker. It uses MicroProfile Reactive Messaging standards for robust, asynchronous communication in microservices architectures.

You can fine-tune your application's interaction with Kafka by configuring the connector in the xref:microprofile-config-properties.adoc#react[microprofile-config.properties] file, as shown in the following example.

----
mp.messaging.connector.liberty-kafka.bootstrap.servers=localhost:9082
----

By configuring a MicroProfile application as shown in the example, to connect to a Kafka broker at `localhost:9082` for messaging. The application is able to send and receive messages through Kafka, facilitating event-driven communication.


You can define a channel to use this connector, directly linking a message channel to Kafka, as shown in the following example.
----
mp.messaging.incoming.myChannel.connector=liberty-kafka
----
By setting up a channel as shown in the example, you connect a message channel directly to Kafka, which gives you precise control over the messaging channels. You can specify attributes such as `bootstrap.servers` for connection and `topic` for message direction, enhancing your application's ability to scale and remain robust by efficiently managing messages.
The `liberty-kafka` connector enables applications to send and receive messages from an https://kafka.apache.org/[Apache Kafka broker]. It uses MicroProfile Reactive Messaging standards for robust, asynchronous communication in microservices architectures.

Integrate Kafka with Open Liberty by following these steps:

1. <<#connection,Configure the Kafka broker connection>>
2. <<#define,Define channels for messaging>>
3. <<#includelib,Include Kafka client libraries>>

4. <<#consec,Configure security for the liberty-kafka connector>>

[#connection]
=== 1. Configure the Kafka broker connection
Expand All @@ -58,6 +43,8 @@ In the `microprofile-config.properties` file, specify the Kafka broker addresses
----
mp.messaging.connector.liberty-kafka.bootstrap.servers=myKafkaBroker:9092
----
By configuring a MicroProfile application as shown in the example, to connect to a Kafka broker at `myKafkaBroker:9092` for messaging. The application is able to send and receive messages through Kafka, facilitating event-driven communication.


[#define]
=== 2. Define channels for messaging
Expand All @@ -74,13 +61,20 @@ mp.messaging.outgoing.myChannel.connector=liberty-kafka
mp.messaging.outgoing.myChannel.topic=myTopicName.
----

By setting up a channel as shown in the examples, you connect a message channel directly to Kafka, which gives you precise control over the messaging channels. You can specify attributes such as `bootstrap.servers` for connection and `topic` for message direction, enhancing your application's ability to scale and remain robust by efficiently managing messages.

For more information on Liberty-Kafka connector options and channel properties, see xref:liberty-kafka-connector-channel-properties.adoc[Liberty-Kafka connector options and channel properties].

[#includelib]
=== 3. Include Kafka client libraries

To integrate Kafka into your application environment by using Open Liberty, choose one of the following methods based on your requirement.
To integrate Kafka into your application environment by using Open Liberty, choose one of the following methods based on your requirement:

* <<#kafkaappdep,Include Kafka libraries as an application dependency>>
* <<#kafkashrddep,Include Kafka libraries as a shared library>>


[#kafkaappdep]
==== Include Kafka libraries as an application dependency

To use the Kafka connector provided by Open Liberty, you must include the Kafka client API jar in your application.
Expand All @@ -98,6 +92,7 @@ If you are building your application with Maven, add the Kafka client dependency

This approach integrates Kafka client libraries directly into your application. It does not require any additional server configuration for permissions, simplifying deployment and configuration management.

[#kafkashrddep]
==== Include Kafka libraries as a shared library

You can integrate Kafka client libraries as a shared resource within the Open Liberty server. This approach is useful for situations where several applications on the same server instance require the Kafka client libraries. It effectively minimizes duplication.
Expand Down Expand Up @@ -147,6 +142,9 @@ To configure these permissions, you can use the `server.xml` configuration file.
<javaPermission codebase="${kafkaCodebase}" className="javax.security.auth.AuthPermission" name="modifyPrivateCredentials"/>
----

[#consec]
=== 4. Configure security for the liberty-kafka connector

For more information on security and authentication methods, see xref:liberty-kafka-connector-config-security.adoc[Kafka connector security configuration].


Expand All @@ -166,9 +164,7 @@ mp.messaging.incoming.foo.value.deserializer=org.apache.kafka.common.serializati

The `kafkabrokerhost:9092` Kafka broker address, the `foo-reader` consumer group ID, and the deserializers for both key and value are `org.apache.kafka.common.serialization.StringDeserializer`, indicating that both keys and values are expected to be strings.

This configuration is essential for retrieving messages from the specified topic, facilitating the building of reactive applications that can efficiently process data streams.

Similarly, the following example of how to set up a microservice to send messages to a Kafka broker.
Similarly, the following example shows you how to set up a microservice to send messages to a Kafka broker by using MicroProfile Reactive Messaging and the liberty-kafka connector.
----
mp.messaging.outgoing.bar.connector=liberty-kafka
mp.messaging.outgoing.bar.bootstrap.servers=kafkabrokerhost:9092
Expand All @@ -182,30 +178,24 @@ The application gains the ability to offload messages to the Kafka topic `bar`.

For more information on `liberty-kafka` connector options and channel properties, see xref:liberty-kafka-connector-channel-properties.adoc[Liberty-kafka connector options and channel properties].

For more information, see link:/guides/microprofile-reactive-messaging.html#creating-the-consumer-in-the-inventory-microservice[Creating the consumer in the inventory microservice] in the Creating reactive Java microservices guide.

[#troubleshooting]
== Troubleshooting

To troubleshoot the `liberty-kafka` connector, address key issues like Kafka connectivity, managing multiple server instances, and giving distinct identifiers to producers and consumers. Make sure that the `bootstrap.servers` are configured correctly for connection. Each consumer has a distinct `group.id` to prevent conflicts, and producers need a unique `client.id` to av o id identifier overlap.
To troubleshoot the `liberty-kafka` connector, address key issues like Kafka connectivity, managing multiple server instances, and giving distinct identifiers to producers and consumers. Make sure that the `bootstrap.servers` are configured correctly for connection. Each consumer has a distinct `group.id` to prevent conflicts, and producers need a distinct `client.id` to avoid identifier overlap.

=== Multiple server instances

If you start multiple instances of Open Liberty with the same application, you must assign a distinct `group.id` to each channel for every server instance. This requirement applies to all incoming channels. Without a distinct `group.id` on each server instance, the server will block any new connections to a topic after the first connection is established. This policy makes sure that each connection to a topic is distinct and properly managed across all server instances.

=== Multiple Reactive Messaging applications using the same Kafka server

Deploying multiple applications with a Kafka client to Liberty, all connecting to the same Kafka server, can cause errors. These errors stem from conflicting identifiers that are used by both Kafka Producers and Consumers within the applications.

This is due to how Kafka generates the `client.id` for both. Consumers generate identifiers based on their `group.id` or their `client.id`.

- For consumers, it is suggested that you create a distinct `group.id` for each incoming channel.
When multiple applications with a Kafka client are deployed to Open Liberty and connect to the same Kafka server, errors can happen. The errors come from conflicting identifiers that both Kafka producers and consumers use within these applications. Kafka generates the `client.id` for both, that lead to these conflicts, especially since consumers determine their identifiers by using either their `group.id` or `client.id`.

- For producers, it is suggested that you create a distinct `client.id` for each outgoing channel.
To mitigate these conflicts, it is essential to make sure that each consumer channel has a distinct `group.id` and each producer channel has a distinct `client.id`. However, specifying these attributes directly on the `liberty-kafka` connector is not an effective solution and must be avoided.

Specifying either attribute on the `liberty-kafka` Connector does not resolve the issue and is not advised.

These steps are designed to diagnose and resolve common challenges that are encountered integrating Kafka with Open Liberty. They help in facilitating the smooth functioning of your microservices architecture.

For more information, see link:/guides/microprofile-reactive-messaging.html#creating-the-consumer-in-the-inventory-microservice[Creating the consumer in the inventory microservice] in the Creating reactive Java microservices guide.
These steps aim to identify and address common challenges that arise during the integration of Kafka with Open Liberty. They help in facilitating the smooth functioning of your microservices architecture.

For more information on Apache Kafka, see the https://kafka.apache.org/documentation.html#gettingStarted[Apache Kafka documentation].

Expand Down
4 changes: 2 additions & 2 deletions modules/ROOT/pages/metrics-list.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
:mp-4-0: feature:mpMetrics-4.0[display=MicroProfile Metrics 4.0]
:mp-5-0: feature:mpMetrics-5.0[display=MicroProfile Metrics 5.0]
:mp-ft-3-0: feature:mpFaultTolerance-3.0[display=MicroProfile Fault Tolerance 3.0]
:connector-metric-features: feature:mpMetrics[display=MicroProfile Metrics] and feature:mpReactiveMessaging[display=MicroProfile Reactive Messaging]
:connector-metric-features: feature:mpMetrics[display=MicroProfile Metrics] and feature:mpReactiveMessaging[display=MicroProfile Reactive Messaging 3.0]
:base-metric-features: feature:mpMetrics[display=MicroProfile Metrics]
:vendor-metric-features: feature:mpMetrics[display=MicroProfile Metrics]
:ft-metric-features: feature:mpMetrics[display=MicroProfile Metrics] and feature:mpFaultTolerance[display=MicroProfile Fault Tolerance]
Expand Down Expand Up @@ -662,7 +662,7 @@ This metric is a gauge.
|mp_messaging_message_count{channel="<channelName>",mp_scope="base"}
|The number of messages sent on the named channel.
|Base metric, but available only when MP Metrics and MP Reactive Messaging features are enabled.
|{connector-metric-features}
|{connector-metric-features}
|{mp-4-0}

|requestTiming.activeRequestCount
Expand Down
2 changes: 1 addition & 1 deletion modules/ROOT/pages/microprofile-config-properties.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ The following MicroProfile Config properties can be specified when MicroProfile
|`mp.messaging.connector._connector-id_._attribute_`
|Specifies a connector attribute value.

If an attribute is specified for both the channel and its corresponding connector, the attribute set for the channel overrides that of the connector.
If an attribute is specified for both the channel and its corresponding connector, the value that is set for the channel overrides the value for the connector.
|Application startup
|`mp.messaging.connector.io.openliberty.kafka.bootstrap.servers=mybrokerhostname`

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
You can use MicroProfile Config properties to provide configuration values for MicroProfile Reactive Messaging. For more information, see xref:ROOT:microprofile-config-properties.adoc#react[MicroProfile Config Properties: Reactive Messaging].

Open Liberty provides a connector for Reactive Messaging to connect to a Kafka server, offering an asynchronous messaging system for MicroProfile Reactive Messaging to use for storing messages. For more information, see xref:ROOT:liberty-kafka-Connector.adoc[Optimizing Kafka Integration with MicroProfile Messaging].
Open Liberty provides a connector for Reactive Messaging to connect to a Kafka server, offering an asynchronous messaging system for MicroProfile Reactive Messaging to use for storing messages. For more information, see xref:ROOT:liberty-kafka-connector.adoc[Optimizing asynchronous communication with MicroProfile Reactive Messaging].