1.RocketMq安装部署
Linux 安装 RocketMq-CSDN博客
2.添加依赖包
<!-- https://mvnrepository.com/artifact/org.apache.rocketmq/rocketmq-client-apis -->
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-client-java</artifactId>
<version>5.0.5</version>
</dependency>
3.生产者相关代码
package com.lhy.demo.rocketMqGRPC;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.apis.ClientConfiguration;
import org.apache.rocketmq.client.apis.ClientException;
import org.apache.rocketmq.client.apis.ClientServiceProvider;
import org.apache.rocketmq.client.apis.producer.Producer;
import org.apache.rocketmq.client.apis.producer.ProducerBuilder;
import org.apache.rocketmq.client.apis.producer.TransactionChecker;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* <p>
* MyProducer
* </p>
*
* @author ocean
* @version 1.0.0
* @since 2023/11/27 15:33
*/
@Slf4j
@Configuration
public class MyProducerConfig {
private static final String ACCESS_KEY = "yourAccessKey";
private static final String SECRET_KEY = "yourSecretKey";
private static final String ENDPOINTS = "127.0.0.1:9875";
private static volatile Producer PRODUCER;
private static volatile Producer TRANSACTIONAL_PRODUCER;
@Bean(name = "producer")
public Producer producer() throws ClientException {
return getInstance("normalTopic");
}
// @Bean(name = "transactionalProducer")
// public Producer transactionalProducer() throws ClientException {
// return getTransactionalInstance(null, "");
// }
private Producer buildProducer(TransactionChecker checker, String... topics