Created
March 22, 2019 19:12
-
-
Save cdbartholomew/82cccc410a782a75ccb192392bfd3c76 to your computer and use it in GitHub Desktop.
Simple java producer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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