In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Import java.util.concurrent.TimeUnit;import org.apache.pulsar.client.api.Producer;import org.apache.pulsar.client.api.PulsarClient;import org.apache.pulsar.client.impl.schema.JSONSchema;public class SendMsgTest {public static void main (String [] args) {String url = "http://192.168.1.48:8080"; Try {/ / the first step is to establish a connection PulsarClient client = PulsarClient.builder () .serviceUrl (url) .connectionTimeout (10Med TimeUnit.SECONDS) .build () / / the second step is to create a producer object / / specify the format of sending data (see Pulsar schemas for details) Producer producer=client.newProducer (JSONSchema.of (UserModel.class)) .topic ("my-tenant/my-namespace/testschema-topic") .sendTimeout (10 TimeUnit.SECONDS) .producerName ("senduser") .create () UserModel userModel=new UserModel (); userModel.setName ("testmsg"); userModel.setAge (21); producer.send (userModel); / / synchronous send producer.sendAsync (userModel) asynchronously send System.out.print ("send ok"); client.close ();} catch (Exception e) {e.printStackTrace () }}}
Public class UserModel {
Private String name;private int age;public String getName () {return name;} public void setName (String name) {this.name = name;} public int getAge () {return age;} public void setAge (int age) {this.age = age;}
}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.