-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cef1c66
commit 303850c
Showing
7 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/java/com/training/rabbitmq/controller/DemoRabbitMqController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.training.rabbitmq.controller; | ||
|
||
import io.swagger.annotations.ApiOperation; | ||
|
||
import javax.servlet.http.HttpSession; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.training.core.dto.ResultDataDto; | ||
import com.training.rabbitmq.sender.DemoRabbitMqSender; | ||
|
||
/** | ||
* 测试Rabbit MQ | ||
*/ | ||
@RestController | ||
@RequestMapping(value="/rabbitmq") | ||
public class DemoRabbitMqController { | ||
|
||
@Autowired | ||
private DemoRabbitMqSender demoRabbitMqSender; | ||
|
||
/** | ||
* 发送测试消息队列 | ||
*/ | ||
@ApiOperation(value="发送测试消息队列", notes="addEntity") | ||
@RequestMapping(value = "/addRabbitMq", method = RequestMethod.GET) | ||
public @ResponseBody ResultDataDto addEntity(HttpSession httpSession) { | ||
demoRabbitMqSender.send("jkljklkjljjkljl"); | ||
return ResultDataDto.addAddSuccess(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.training.rabbitmq.dto; | ||
|
||
public class DemoRabbitMqDto { | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/training/rabbitmq/receiver/DemoRabbitMqReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.training.rabbitmq.receiver; | ||
|
||
import org.springframework.amqp.rabbit.annotation.RabbitHandler; | ||
import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* 消息队列接收类 | ||
*/ | ||
@Component | ||
@RabbitListener(queues = "hello") | ||
public class DemoRabbitMqReceiver { | ||
|
||
@RabbitHandler | ||
public void process(String content) { | ||
System.out.println("Receiver : " + content); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/training/rabbitmq/sender/DemoRabbitMqSender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.training.rabbitmq.sender; | ||
|
||
import org.springframework.amqp.core.AmqpTemplate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class DemoRabbitMqSender { | ||
|
||
@Autowired | ||
private AmqpTemplate rabbitTemplate; | ||
|
||
public void send(String content) { | ||
System.out.println("Sender : " + content); | ||
this.rabbitTemplate.convertAndSend("hello", content); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters