Skip to content

Commit

Permalink
[ISSUE apache#4941] Producer example add the default NamesrvAddr
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsm committed Sep 8, 2022
1 parent ed9c775 commit f3a0f4c
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,28 @@
import org.apache.rocketmq.remoting.common.RemotingHelper;

public class Producer {

public static final String PRODUCER_GROUP = "ProducerGroupName";
public static final String DEFAULT_NAMESRVADDR = "127.0.0.1:9876";
public static final String TOPIC = "TopicTest";
public static final String TAG = "TagA";


public static void main(String[] args) throws MQClientException, InterruptedException {

DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
producer.start();
DefaultMQProducer producer = new DefaultMQProducer(PRODUCER_GROUP);

// Uncomment the following line while debugging, namesrvAddr should be set to your local address
//producer.setNamesrvAddr(DEFAULT_NAMESRVADDR);

producer.start();
for (int i = 0; i < 128; i++)
try {
{
Message msg = new Message("TopicTest",
"TagA",
"OrderID188",
"Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
Message msg = new Message(TOPIC, TAG, "OrderID188", "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
SendResult sendResult = producer.send(msg);
System.out.printf("%s%n", sendResult);
}

} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit f3a0f4c

Please sign in to comment.