|
| 1 | +diff --git a/rabbitmq-custom-formula-source/pom.xml b/rabbitmq-custom-formula-source/pom.xml |
| 2 | +index 69e071a..f3fab15 100644 |
| 3 | +--- a/rabbitmq-custom-formula-source/pom.xml |
| 4 | ++++ b/rabbitmq-custom-formula-source/pom.xml |
| 5 | +@@ -16,25 +16,10 @@ |
| 6 | + <properties> |
| 7 | + <java.version>17</java.version> |
| 8 | + </properties> |
| 9 | +- <dependencyManagement> |
| 10 | +- <dependencies> |
| 11 | +- <dependency> |
| 12 | +- <groupId>com.azure.spring</groupId> |
| 13 | +- <artifactId>spring-cloud-azure-dependencies</artifactId> |
| 14 | +- <version>5.22.0</version> |
| 15 | +- <type>pom</type> |
| 16 | +- <scope>import</scope> |
| 17 | +- </dependency> |
| 18 | +- </dependencies> |
| 19 | +- </dependencyManagement> |
| 20 | + <dependencies> |
| 21 | + <dependency> |
| 22 | +- <groupId>com.azure.spring</groupId> |
| 23 | +- <artifactId>spring-cloud-azure-starter</artifactId> |
| 24 | +- </dependency> |
| 25 | +- <dependency> |
| 26 | +- <groupId>com.azure.spring</groupId> |
| 27 | +- <artifactId>spring-messaging-azure-servicebus</artifactId> |
| 28 | ++ <groupId>org.springframework.boot</groupId> |
| 29 | ++ <artifactId>spring-boot-starter-amqp</artifactId> |
| 30 | + </dependency> |
| 31 | + |
| 32 | + <dependency> |
| 33 | +diff --git a/rabbitmq-custom-formula-source/src/main/java/com/example/messagingrabbitmq/MessagingRabbitmqApplication.java b/rabbitmq-custom-formula-source/src/main/java/com/example/messagingrabbitmq/MessagingRabbitmqApplication.java |
| 34 | +index c2568a3..44e610a 100644 |
| 35 | +--- a/rabbitmq-custom-formula-source/src/main/java/com/example/messagingrabbitmq/MessagingRabbitmqApplication.java |
| 36 | ++++ b/rabbitmq-custom-formula-source/src/main/java/com/example/messagingrabbitmq/MessagingRabbitmqApplication.java |
| 37 | +@@ -1,15 +1,10 @@ |
| 38 | + package com.example.messagingrabbitmq; |
| 39 | + |
| 40 | +-import com.azure.core.credential.TokenCredential; |
| 41 | +-import com.azure.core.exception.ResourceNotFoundException; |
| 42 | +-import com.azure.messaging.servicebus.administration.ServiceBusAdministrationClient; |
| 43 | +-import com.azure.messaging.servicebus.administration.ServiceBusAdministrationClientBuilder; |
| 44 | +-import com.azure.messaging.servicebus.administration.models.QueueProperties; |
| 45 | +-import com.azure.spring.cloud.autoconfigure.implementation.servicebus.properties.AzureServiceBusProperties; |
| 46 | + import org.springframework.boot.SpringApplication; |
| 47 | + import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 48 | + import org.springframework.context.ConfigurableApplicationContext; |
| 49 | + import org.springframework.context.annotation.Bean; |
| 50 | ++import org.springframework.amqp.core.Queue; |
| 51 | + |
| 52 | + @SpringBootApplication |
| 53 | + public class MessagingRabbitmqApplication { |
| 54 | +@@ -23,21 +18,8 @@ public class MessagingRabbitmqApplication { |
| 55 | + } |
| 56 | + |
| 57 | + @Bean |
| 58 | +- ServiceBusAdministrationClient serviceBusAdministrationClient( |
| 59 | +- AzureServiceBusProperties properties, |
| 60 | +- TokenCredential credential) { |
| 61 | +- return new ServiceBusAdministrationClientBuilder() |
| 62 | +- .credential(properties.getFullyQualifiedNamespace(), credential) |
| 63 | +- .buildClient(); |
| 64 | +- } |
| 65 | +- |
| 66 | +- @Bean |
| 67 | +- QueueProperties queue(ServiceBusAdministrationClient adminClient) { |
| 68 | +- try { |
| 69 | +- return adminClient.getQueue(queueName); |
| 70 | +- } catch (ResourceNotFoundException e) { |
| 71 | +- return adminClient.createQueue(queueName); |
| 72 | +- } |
| 73 | ++ public Queue queue() { |
| 74 | ++ return new Queue(queueName, true); |
| 75 | + } |
| 76 | + |
| 77 | + } |
| 78 | +diff --git a/rabbitmq-custom-formula-source/src/main/java/com/example/messagingrabbitmq/Producer.java b/rabbitmq-custom-formula-source/src/main/java/com/example/messagingrabbitmq/Producer.java |
| 79 | +index ce09812..db743c7 100644 |
| 80 | +--- a/rabbitmq-custom-formula-source/src/main/java/com/example/messagingrabbitmq/Producer.java |
| 81 | ++++ b/rabbitmq-custom-formula-source/src/main/java/com/example/messagingrabbitmq/Producer.java |
| 82 | +@@ -1,26 +1,25 @@ |
| 83 | + package com.example.messagingrabbitmq; |
| 84 | + |
| 85 | +-import org.springframework.messaging.Message; |
| 86 | ++import org.springframework.amqp.core.Message; |
| 87 | + import org.springframework.stereotype.Component; |
| 88 | +-import com.azure.spring.messaging.servicebus.core.ServiceBusTemplate; |
| 89 | +-import org.springframework.messaging.support.MessageBuilder; |
| 90 | ++import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| 91 | + import org.springframework.beans.factory.annotation.Autowired; |
| 92 | + |
| 93 | + @Component |
| 94 | + public class Producer { |
| 95 | + |
| 96 | + @Autowired |
| 97 | +- private final ServiceBusTemplate serviceBusTemplate; |
| 98 | ++ private final RabbitTemplate rabbitTemplate; |
| 99 | + |
| 100 | +- public Producer(ServiceBusTemplate serviceBusTemplate) { |
| 101 | +- this.serviceBusTemplate = serviceBusTemplate; |
| 102 | ++ public Producer(RabbitTemplate rabbitTemplate) { |
| 103 | ++ this.rabbitTemplate = rabbitTemplate; |
| 104 | + } |
| 105 | + |
| 106 | + public void run() { |
| 107 | + for (int i = 0; i < 10; i++) { |
| 108 | + System.out.println("Sending message..." + i); |
| 109 | + String responseString = "test " + i; |
| 110 | +- serviceBusTemplate.send(MessagingRabbitmqApplication.queueName, MessageBuilder.withPayload(responseString).build()); |
| 111 | ++ rabbitTemplate.convertAndSend(MessagingRabbitmqApplication.queueName, new Message(responseString.getBytes())); |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | +\ No newline at end of file |
| 116 | +diff --git a/rabbitmq-custom-formula-source/src/main/resources/application.properties b/rabbitmq-custom-formula-source/src/main/resources/application.properties |
| 117 | +index d9f0baf..93541af 100644 |
| 118 | +--- a/rabbitmq-custom-formula-source/src/main/resources/application.properties |
| 119 | ++++ b/rabbitmq-custom-formula-source/src/main/resources/application.properties |
| 120 | +@@ -1,4 +1,4 @@ |
| 121 | +-spring.cloud.azure.servicebus.entity-type=queue |
| 122 | +-spring.cloud.azure.servicebus.namespace= |
| 123 | +-spring.cloud.azure.credential.managed-identity-enabled= true |
| 124 | +-spring.cloud.azure.credential.client-id= |
| 125 | +\ No newline at end of file |
| 126 | ++spring.rabbitmq.password=secret |
| 127 | ++spring.rabbitmq.username=myuser |
| 128 | ++spring.rabbitmq.host=localhost |
| 129 | ++spring.rabbitmq.port=5671 |
0 commit comments