feat:() 新增MQ生产者 和 修改kafka生产者的信息
parent
0e391451b0
commit
d02813f7e4
|
@ -1,12 +1,14 @@
|
||||||
package com.muyu.processing.controller;
|
package com.muyu.processing.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import cn.hutool.json.JSONObject;
|
||||||
import com.muyu.common.core.constant.KafkaConstants;
|
import com.muyu.common.core.constant.KafkaConstants;
|
||||||
|
import com.muyu.common.core.utils.uuid.UUID;
|
||||||
import com.muyu.common.kafka.config.KafkaProducerConfig;
|
import com.muyu.common.kafka.config.KafkaProducerConfig;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.apache.kafka.clients.producer.KafkaProducer;
|
import org.apache.kafka.clients.producer.KafkaProducer;
|
||||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
import org.apache.kafka.common.protocol.types.Field;
|
import org.apache.kafka.common.protocol.types.Field;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
@ -14,6 +16,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 消息队列测试-生产者
|
||||||
* @Author:杨鹏
|
* @Author:杨鹏
|
||||||
* @Package:com.muyu.processing.controller
|
* @Package:com.muyu.processing.controller
|
||||||
* @Project:car-cloud-server
|
* @Project:car-cloud-server
|
||||||
|
@ -29,10 +32,44 @@ public class TestKafka {
|
||||||
@Resource
|
@Resource
|
||||||
private KafkaProducer<String, String> kafkaProducer;
|
private KafkaProducer<String, String> kafkaProducer;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RabbitTemplate rabbitTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送Kafka消息
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
@GetMapping("/send")
|
@GetMapping("/send")
|
||||||
public void sendMsg(){
|
public String sendMsg(){
|
||||||
ProducerRecord<String, String> producerRecord = new ProducerRecord<>("zeshi", "你好啊");
|
JSONObject entries = new JSONObject();
|
||||||
|
entries.set("vin","vin123468");
|
||||||
|
entries.set("name","宝马");
|
||||||
|
String entriesString = entries.toString();
|
||||||
|
ProducerRecord<String, String> producerRecord = new ProducerRecord<>("zeshi", entriesString);
|
||||||
kafkaProducer.send(producerRecord);
|
kafkaProducer.send(producerRecord);
|
||||||
|
return "OK";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送MQ消息
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
@GetMapping("/sendMQ")
|
||||||
|
public String sendMQ(){
|
||||||
|
rabbitTemplate.convertAndSend("long_time_no_see","晨哀,好久不见",message -> {
|
||||||
|
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||||
|
return message;
|
||||||
|
});
|
||||||
|
return "OK";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送MQ队列消息
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
@GetMapping("/sendDui")
|
||||||
|
public String sedDui() {
|
||||||
|
rabbitTemplate.convertAndSend("myExchange","Im.fine","");
|
||||||
|
return "OK";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue