Skip to content

Commit 8626358

Browse files
authored
Strangler fig (#6)
* Support guide CAMS * Support guide config for different senders * app service environment variable for email request service * Spring Cloud Stream to send messages to Azure Service Bus * send email request from CAMS * Process email response in CAMS * documentation
1 parent 0194de4 commit 8626358

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+496
-55
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"AZURE_ACTIVE_DIRECTORY_CREDENTIAL_TENANT_ID": "",
2929
"AZURE_SERVICEBUS_NAMESPACE": "",
3030
"AZURE_SERVICEBUS_EMAIL_REQUEST_QUEUE_NAME": "",
31-
"AZURE_SERVICEBUS_EMAIL_RESPONSE_QUEUE_NAME": ""
31+
"AZURE_SERVICEBUS_EMAIL_RESPONSE_QUEUE_NAME": "",
32+
"CONTOSO_SUPPORT_GUIDE_REQUEST_SERVICE": ""
3233
}
3334
},
3435
{

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ The environment name should be less than 18 characters and must be comprised of
4949
azd env new <pick_a_name>
5050
```
5151

52-
Enable the AZD Terraform provider:
53-
54-
```shell
55-
azd config set alpha.terraform on
56-
```
57-
5852
Select the subscription that will be used for the deployment:
5953

6054
```shell
@@ -67,6 +61,12 @@ Set the Azure region to be used:
6761
azd env set AZURE_LOCATION <pick_a_region>
6862
```
6963

64+
Optional: Set the App Registration Service management reference:
65+
66+
```shell
67+
azd env set AZURE_SERVICE_MANAGEMENT_REFERENCE <service_management_reference>
68+
```
69+
7070
## Create the Azure resources and deploy the code
7171

7272
Run the following command to create the Azure resources and deploy the code (about 15-minutes to complete):

apps/contoso-fiber/pom.xml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<description>Customer Account Management System</description>
1919

2020
<dependencies>
21+
<dependency>
22+
<groupId>org.springframework.cloud</groupId>
23+
<artifactId>spring-cloud-stream</artifactId>
24+
</dependency>
2125
<dependency>
2226
<groupId>org.springframework.boot</groupId>
2327
<artifactId>spring-boot-starter-web</artifactId>
@@ -100,7 +104,6 @@
100104
<dependency>
101105
<groupId>com.fasterxml.jackson.core</groupId>
102106
<artifactId>jackson-databind</artifactId>
103-
<version>2.15.2</version>
104107
</dependency>
105108

106109
<dependency>
@@ -123,11 +126,6 @@
123126
<artifactId>commons-lang3</artifactId>
124127
</dependency>
125128

126-
<dependency>
127-
<groupId>com.azure</groupId>
128-
<artifactId>azure-messaging-servicebus</artifactId>
129-
</dependency>
130-
131129
<dependency>
132130
<groupId>com.azure.spring</groupId>
133131
<artifactId>spring-cloud-azure-stream-binder-servicebus</artifactId>
@@ -141,12 +139,6 @@
141139

142140
</dependencies>
143141

144-
<dependencyManagement>
145-
<dependencies>
146-
147-
</dependencies>
148-
</dependencyManagement>
149-
150142
<build>
151143
<finalName>cams</finalName>
152144
<plugins>

apps/contoso-fiber/src/main/java/com/contoso/cams/CamsApplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@SpringBootApplication
1919
@EnableCaching
2020
public class CamsApplication {
21+
2122
public static void main(String[] args) {
2223
SpringApplication.run(CamsApplication.class, args);
2324
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.contoso.cams.config;
2+
3+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
4+
import org.springframework.cloud.stream.function.StreamBridge;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
8+
import com.contoso.cams.services.SupportGuideQueueLoadDemo;
9+
import com.contoso.cams.services.SuportGuideDeadLetterDemo;
10+
import com.contoso.cams.services.SupportGuideEmailSender;
11+
import com.contoso.cams.services.SupportGuideQueueSender;
12+
import com.contoso.cams.services.SupportGuideSender;
13+
14+
@Configuration
15+
public class SupportGuideSenderConfig {
16+
17+
@Bean
18+
@ConditionalOnProperty(prefix = "contoso.suport-guide.request", name = "service", havingValue = "queue")
19+
SupportGuideSender supportGuideQueueSender(StreamBridge streamBridge) {
20+
return new SupportGuideQueueSender(streamBridge);
21+
}
22+
23+
@Bean
24+
@ConditionalOnProperty(prefix = "contoso.suport-guide.request", name = "service", havingValue = "email")
25+
SupportGuideSender supportGuideEmailSender() {
26+
return new SupportGuideEmailSender();
27+
}
28+
29+
@Bean
30+
@ConditionalOnProperty(prefix = "contoso.suport-guide.request", name = "service", havingValue = "demo-load")
31+
SupportGuideSender supportGuideQueueLoadDemo(StreamBridge streamBridge) {
32+
return new SupportGuideQueueLoadDemo(streamBridge);
33+
}
34+
35+
@Bean
36+
@ConditionalOnProperty(prefix = "contoso.suport-guide.request", name = "service", havingValue = "demo-dead-letter")
37+
SupportGuideSender suportGuideDeadLetterDemo(StreamBridge streamBridge) {
38+
return new SuportGuideDeadLetterDemo(streamBridge);
39+
}
40+
}

apps/contoso-fiber/src/main/java/com/contoso/cams/serviceplan/ServicePlanController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,4 @@ public String updateServicePlan(Model model, @ModelAttribute("servicePlan") Serv
6363
return "pages/plans/notfound";
6464
}
6565
}
66-
6766
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.contoso.cams.services;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.cloud.stream.function.StreamBridge;
6+
7+
public class SuportGuideDeadLetterDemo implements SupportGuideSender {
8+
9+
private static final Logger log = LoggerFactory.getLogger(SuportGuideDeadLetterDemo.class);
10+
private static final String EMAIL_REQUEST_QUEUE = "produceemailrequest-out-0";
11+
12+
private final StreamBridge streamBridge;
13+
14+
public SuportGuideDeadLetterDemo(StreamBridge streamBridge) {
15+
this.streamBridge = streamBridge;
16+
}
17+
18+
@Override
19+
public void send(String to, String guideUrl, Long requestId) {
20+
final String bogusMessage = "This is a bogus message for request id " + requestId;
21+
22+
log.info("EmailRequest: {}", bogusMessage);
23+
24+
streamBridge.send(EMAIL_REQUEST_QUEUE, bogusMessage);
25+
26+
log.info("Message sent to the queue");
27+
}
28+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.contoso.cams.services;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
6+
public class SupportGuideEmailSender implements SupportGuideSender {
7+
8+
private static final Logger log = LoggerFactory.getLogger(SupportGuideEmailSender.class);
9+
10+
@Override
11+
public void send(String to, String guideUrl, Long requestId) {
12+
log.info("Sending guide to {} with url {} by email for request id {}", to, guideUrl, requestId);
13+
}
14+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.contoso.cams.services;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.cloud.stream.function.StreamBridge;
6+
7+
import com.contoso.cams.protobuf.email.v1.EmailRequest;
8+
9+
public class SupportGuideQueueLoadDemo implements SupportGuideSender {
10+
11+
private static final Logger log = LoggerFactory.getLogger(SupportGuideQueueLoadDemo.class);
12+
private static final String EMAIL_REQUEST_QUEUE = "produceemailrequest-out-0";
13+
14+
private final StreamBridge streamBridge;
15+
16+
public SupportGuideQueueLoadDemo(StreamBridge streamBridge) {
17+
this.streamBridge = streamBridge;
18+
}
19+
20+
@Override
21+
public void send(String to, String guideUrl, Long requestId) {
22+
EmailRequest emailRequest = EmailRequest.newBuilder()
23+
.setRequestId(requestId)
24+
.setEmailAddress(to)
25+
.setUrlToManual(guideUrl)
26+
.build();
27+
28+
log.info("EmailRequest: {}", emailRequest);
29+
30+
var message = emailRequest.toByteArray();
31+
32+
for (int i = 0; i < 1_000; i++) {
33+
streamBridge.send(EMAIL_REQUEST_QUEUE, message);
34+
}
35+
36+
log.info("Messages sent to the queue");
37+
}
38+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.contoso.cams.services;
2+
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
import org.springframework.cloud.stream.function.StreamBridge;
6+
7+
import com.contoso.cams.protobuf.email.v1.EmailRequest;
8+
9+
public class SupportGuideQueueSender implements SupportGuideSender {
10+
11+
private static final Logger log = LoggerFactory.getLogger(SupportGuideQueueSender.class);
12+
private static final String EMAIL_REQUEST_QUEUE = "produceemailrequest-out-0";
13+
14+
private final StreamBridge streamBridge;
15+
16+
public SupportGuideQueueSender(StreamBridge streamBridge) {
17+
this.streamBridge = streamBridge;
18+
}
19+
20+
@Override
21+
public void send(String to, String guideUrl, Long requestId) {
22+
EmailRequest emailRequest = EmailRequest.newBuilder()
23+
.setRequestId(requestId)
24+
.setEmailAddress(to)
25+
.setUrlToManual(guideUrl)
26+
.build();
27+
28+
log.info("EmailRequest: {}", emailRequest);
29+
30+
var message = emailRequest.toByteArray();
31+
streamBridge.send(EMAIL_REQUEST_QUEUE, message);
32+
33+
log.info("Message sent to the queue");
34+
}
35+
}

0 commit comments

Comments
 (0)