Configuring a client application to connect to a virtual topic
Configure your client applications to connect to the Event Gateway to access your subscriptions.
Using the Integration Agent to create reference code for connecting clients
The Integration Agent in Event Endpoint Management can help you create sample code to use for connecting your client to a virtual topic. After you subscribe to a virtual topic in the catalog, click Get started and follow the instructions to produce ready-to-use code for your application.
This option is useful if you want to avoid manual configuration steps.
Configuring a client
The Event Gateway manages access to virtual topics in Event Endpoint Management. Configure your client applications to connect to the Event Gateway by using standard Kafka client configuration options.
The way that you provide the configuration settings to your client varies from client to client. However, the following settings are common for every client:
-
Bootstrap servers: Your Event Gateway endpoint addresses that provide access to a virtual topic. -
Security mechanism: Set asSASL_SSLif username and password are used in the subscription. Set asSSLif mTLS is used without a username and password. -
SSL configuration: The Event Gateway exposes only a TLS-secured endpoint for clients to connect to. Configure your client to trust this certificate. -
SASLcredentials : IfSASL_SSLis specified as theSASL mechanism, then setSASL username, andSASL passwordwith the values retrieved when yousubscribed to the virtual topic. -
Topic name: The name of the virtual topic you want your application to use.
- Log in to the Event Endpoint Management UI by using your login credentials.
- In the navigation pane, click Catalog.
- Click the topic that you want to subscribe to.
- In the Virtual topics section, click the virtual topic that you want to use. The name of the virtual topic is the name displayed in the card.
- The bootstrap server addresses and server certificate are available in the Selected virtual topic server URLs section.
myClientApplication1: <GROUP_ID>=BOB, <CLIENT_ID>=ABC
myClientApplication2: <GROUP_ID>=BOB, <CLIENT_ID>=ABCUsing different client ID
values within the same subscription and group ID can cause connection failures or runtime errors.Testing virtual topics with the Code accelerator
Before using the downloaded configuration for a virtual topic in a complex application, you can test the virtual topic configuration using the code accelerator samples.
Example kcat test of consumer virtual topic
kcat is an open source test tool for Kafka. Follow these steps to test a SASL secured virtual topic with the kcat code accelerator sample:
- Install kcat on a system that has network access to your Event Gateway.
- Log in to the Event Endpoint Management UI by using your login credentials.
- In the navigation pane, click Catalog.
- Select the virtual topic that you want to test.
- If you do not already have a subscription to this virtual topic, then subscribe to get a SASL username and password.
- Expand the Code accelerator section.
- Switch to the kcat tab.
- Copy the kcat sample command and replace the placeholder variables:
<GROUP_ID>- Replace with a unique string.<CLIENT_ID>- Replace with a unique string.<CREDENTIALS_USERNAME>- set to your SASL username.<CREDENTIALS_PASSWORD>- set to your SASL password.
Note: When you set the client ID, reuse the same values across all clients that share the same application and group ID. -
Run the kcat sample command. For example:
kcat -J -G group1 \ -b "grp1-gwy1-ibm-egw-example.apps.ibm.com:443,grp1-gwy1-ibm-egw-example.ibm.com:443,grp1-gwy1-ibm-egw-example.ibm.com:443" \ -X client.id=client1 \ -X security.protocol="SASL_SSL" \ -X ssl.ca.pem="-----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----" \ -X sasl.mechanisms="PLAIN" \ -X sasl.username="eem-7f0c68e8-3c40-432b-a926-921080c9661d" \ -X sasl.password="f742c545-0ce2-4958-a801-114f242c3d3e" \ "noop"; : # Note: in some versions of kcat the '-t' flag must precede the topic nameThe kcat command output displays the events that the virtual topic produces. For example:% Waiting for group rebalance % Group group1 rebalanced (memberid client1-730ea6d6-6968-4a8b-9900-8652d4f5e310): assigned: noop [0] % Reached end of topic noop [0] at offset 15 {"topic":"noop","partition":0,"offset":15,"tstype":"create","ts":1754311306587,"broker":1,"key":null,"payload":"Sample message value"} % Reached end of topic noop [0] at offset 16 {"topic":"noop","partition":0,"offset":16,"tstype":"create","ts":1754311308412,"broker":1,"key":null,"payload":"Sample message value"}% Reached end of topic noop [0] at offset 17