Skip to content

Instantly share code, notes, and snippets.

@cdbartholomew
Created March 22, 2019 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdbartholomew/82cccc410a782a75ccb192392bfd3c76 to your computer and use it in GitHub Desktop.
Save cdbartholomew/82cccc410a782a75ccb192392bfd3c76 to your computer and use it in GitHub Desktop.
Simple java producer
import org.apache.pulsar.client.api.*;
import java.io.IOException;
public class simpleProducer {
private static final String SERVICE_URL = "pulsar://ASIAEAST2.GCP.KAFKAESQUE.IO:6650";
public static void main(String[] args) throws IOException
{
// Create client object
PulsarClient client = PulsarClient.builder()
.serviceUrl(SERVICE_URL)
.build();
// Create producer on a topic
Producer<byte[]> producer = client.newProducer()
.topic("persistent://mytenant2/local-asiaeast2-gcp/tc2-messages")
.create();
// Send a message to the topic
producer.send("Hello World".getBytes());
//Close the producer
producer.close();
// Close the client
client.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment