How to Send a Notification to the IBM Message Hub with Java

MessageHubSample.java

import java.util.Properties;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

public final class MessageHubSample {

  public static void main(final String[] args) {
    final Properties props = new Properties();

    props.put("bootstrap.servers", "host:9093");

    props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");

    props.put("security.protocol", "SASL_SSL");

    props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

    final Producer<String, String> producer = new KafkaProducer<>(props);

    producer.send(new ProducerRecord<String, String>("SampleTopic", "Sample Message"));

    producer.close();
  }

}

jaas.conf

KafkaClient {
  com.ibm.messagehub.login.MessageHubLoginModule required
  serviceName="kafka"
  username="username"
  password="password";
};

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s