rocketmq-client5.2手动给生产者和消费者设置access-key和secret-key值
生产者
import org.apache.rocketmq.acl.common.AclClientRPCHook;
import org.apache.rocketmq.acl.common.SessionCredentials;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
public class AclProducer {
public static void main(String[] args) throws Exception {
DefaultMQProducer producer = new DefaultMQProducer("rexel_notice_p1", getAclRPCHook());
producer.setNamesrvAddr("192.168.29.100:9876;192.168.29.101:9876");
producer.start();
Message msg = new Message("rexel_notice", "*", "Hello RocketMQ".getBytes());
SendResult sendResult = producer.send(msg);
System.out.printf("%s%n", sendResult);
producer.shutdown();
}
static AclClientRPCHook getAclRPCHook() {
return new AclClientRPCHook(new SessionCredentials("rexel_developer", "19@ljWo2iUow"));
}
}
消费者代码DefaultMQPushConsumer也需要设置RPCHook,步骤与生产者类似