Contact Us 1-800-596-4880

Apache Kafka 4.4 XML and Maven Support - Mule 4

If you manually code a Mule app in XML either from the Anypoint Studio XML editor or from a text editor, you can get access to the Anypoint Connector for Apache Kafka (Apache Kafka Connector) in your app by adding reference statements to your XML Mule flow and in the Apache Maven pom.xml file.

You can avoid this manual process by using Anypoint Studio. When you add the Apache Kafka Connector in Studio, Studio automatically populates the XML code with the Apache Kafka Connector namespace and schema location, and adds a dependency to the pom.xml file.

Add a Namespace for the Connector

Paste the following into the header of your configuration XML, inside the <mule> tag:

http://www.mulesoft.org/schema/mule/kafka
http://www.mulesoft.org/schema/mule/kafka/current/mule-kafka.xsd

This example shows how the namespace statements are placed in the <mule> XML block:

<mule xmlns:kafka="http://www.mulesoft.org/schema/mule/kafka"
	xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
	xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns:file="http://www.mulesoft.org/schema/mule/file"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core
	http://www.mulesoft.org/schema/mule/core/current/mule.xsd
	http://www.mulesoft.org/schema/mule/file
	http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
	http://www.mulesoft.org/schema/mule/http
	http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
	http://www.mulesoft.org/schema/mule/ee/core
	http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
	http://www.mulesoft.org/schema/mule/kafka
	http://www.mulesoft.org/schema/mule/kafka/current/mule-kafka.xsd">

Add a POM File Dependency

The Apache Maven pom.xml file generated by Anypoint Studio contains dependencies for a Mule app. If you code a Mule app manually, include this XML snippet in your pom.xml file to enable access to this connector:

<dependency>
  <groupId>com.mulesoft.connectors</groupId>
  <artifactId>mule-kafka-connector</artifactId>
  <version>x.x.x</version>
  <classifier>mule-plugin</classifier>
</dependency>

Replace x.x.x with the version that corresponds to the connector you are using.

To obtain the most up-to-date pom.xml file information, access the connector in Anypoint Exchange and click Dependency Snippets.

Next

After completing your namespace and pom.xml file, you can try out the Apache Kafka Examples.

View on GitHub