Skip to content

Commit eb2f93f

Browse files
authored
add formula source (Azure-Samples#14)
1 parent f097bb4 commit eb2f93f

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>3.3.0</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
<groupId>com.example</groupId>
12+
<artifactId>messaging-rabbitmq-source</artifactId>
13+
<version>0.0.1-SNAPSHOT</version>
14+
<name>messaging-rabbitmq-source</name>
15+
<description>Source project for rabbitmq</description>
16+
<properties>
17+
<java.version>17</java.version>
18+
</properties>
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-amqp</artifactId>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-starter-test</artifactId>
28+
<scope>test</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.projectlombok</groupId>
32+
<artifactId>lombok</artifactId>
33+
<scope>provided</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.projectlombok</groupId>
37+
<artifactId>lombok</artifactId>
38+
<version>1.18.24</version>
39+
<scope>provided</scope>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>com.fasterxml.jackson.core</groupId>
44+
<artifactId>jackson-databind</artifactId>
45+
</dependency>
46+
</dependencies>
47+
48+
<build>
49+
<plugins>
50+
<plugin>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-maven-plugin</artifactId>
53+
</plugin>
54+
</plugins>
55+
</build>
56+
57+
</project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.example.messagingrabbitmq;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.context.ConfigurableApplicationContext;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.amqp.core.Queue;
8+
9+
@SpringBootApplication
10+
public class MessagingRabbitmqApplication {
11+
12+
static final String queueName = "queue";
13+
14+
public static void main(String[] args) throws InterruptedException {
15+
ConfigurableApplicationContext applicationContext = SpringApplication.run(MessagingRabbitmqApplication.class);
16+
Producer producer = applicationContext.getBean(Producer.class);
17+
producer.run();
18+
}
19+
20+
@Bean
21+
public Queue queue() {
22+
return new Queue(queueName, true);
23+
}
24+
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.example.messagingrabbitmq;
2+
3+
import org.springframework.amqp.core.Message;
4+
import org.springframework.stereotype.Component;
5+
import org.springframework.amqp.rabbit.core.RabbitTemplate;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
8+
@Component
9+
public class Producer {
10+
11+
@Autowired
12+
private final RabbitTemplate rabbitTemplate;
13+
14+
public Producer(RabbitTemplate rabbitTemplate) {
15+
this.rabbitTemplate = rabbitTemplate;
16+
}
17+
18+
public void run() {
19+
for (int i = 0; i < 10; i++) {
20+
System.out.println("Sending message..." + i);
21+
String responseString = "test " + i;
22+
rabbitTemplate.convertAndSend(MessagingRabbitmqApplication.queueName, new Message(responseString.getBytes()));
23+
}
24+
}
25+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
spring.rabbitmq.password=secret
2+
spring.rabbitmq.username=myuser
3+
spring.rabbitmq.host=localhost
4+
spring.rabbitmq.port=5671

0 commit comments

Comments
 (0)