Skip to content

Commit 11acedd

Browse files
committed
JDK16 -> JDK 11 for Azure Spring Cloud
Updated README Resource loading issue Improved logging WS vs WSS protocol
1 parent 9d4f4d5 commit 11acedd

File tree

7 files changed

+48
-18
lines changed

7 files changed

+48
-18
lines changed

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,30 @@ Via RedisCDC these changes will appear in demo application #1.
2323
2. Make sure you are logged into the Azure CLI
2424
3. Add the Azure Spring Cloud extension to the Azure CLI `az extension add --name spring-cloud` If you already have the extension, make sure it's up to date using `az extension update --name spring-cloud`
2525
2. Create an Azure Spring Cloud instance using `az spring-cloud create -n acrebank -g rdsLroACRE -l northeurope` (this may take a few minutes)
26-
3. Create an App in the newly created Azure Spring Cloud instance using `az spring-cloud app create -n acrebankapp -s acrebank -g rdsLroACRE --assign-endpoint true`
26+
3. Create an App in the newly created Azure Spring Cloud instance using `az spring-cloud app create -n acrebankapp -s acrebank -g rdsLroACRE --assign-endpoint true --runtime-version Java_11`
2727
4. Modify the application.properties so it points to your newly created ACRE instance
28-
5. Rebuild the app using `./mvnw package`
29-
6. Deploy the app to Azure Spring Cloud using `az spring-cloud app deploy -n acrebankapp -s acrebank -g rdsLroAcre --jar-path target/redisbank-0.0.1-SNAPSHOT.jar`
3028

31-
Demo shows
29+
```
30+
spring.redis.host=your ACRE hostname
31+
spring.redis.port=your ACRE port (default: 10000)
32+
spring.redis.password= your ACRE access key
33+
```
3234

35+
5. Modify the application.properties so the websocket config will point to the Azure Spring Cloud app instance endpoint createed in step 3.
36+
37+
```
38+
stomp.host=your ASC app endpoint URL (Default: <appname>-<service-name>.azuremicroservices.io)
39+
stomp.port=443
40+
stomp.protocol=wss
41+
```
42+
43+
6. Rebuild the app using `./mvnw package`
44+
7. Deploy the app to Azure Spring Cloud using `az spring-cloud app deploy -n acrebankapp -s acrebank -g rdsLroAcre --jar-path target/redisbank-0.0.1-SNAPSHOT.jar`
45+
46+
## Troubleshooting tips on Azure Spring Cloud
47+
48+
To get the application logs:
49+
50+
`az spring-cloud app logs -n acrebankapp -g rdsLroAcre -s acrebank`
51+
52+
Note: project is compiled with JDK11 as that's currently the max LTS version that's supported by Azure Spring Cloud. Project will run fine when running locally or on other platforms up to JDK16.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<name>redisbank</name>
1414
<description>Demo project for Spring Boot</description>
1515
<properties>
16-
<java.version>16</java.version>
16+
<java.version>11</java.version>
1717
</properties>
1818
<dependencies>
1919
<dependency>

src/main/java/com/redislabs/demos/redisbank/SerializationUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.redislabs.demos.redisbank;
22

33
import java.io.File;
4+
import java.io.InputStream;
45
import java.text.SimpleDateFormat;
56
import java.util.Collections;
67
import java.util.List;
@@ -25,9 +26,9 @@ public static <T> List<T> loadObjectList(Class<T> type, String fileName) {
2526
try {
2627
CsvSchema bootstrapSchema = CsvSchema.emptySchema().withHeader();
2728
CsvMapper mapper = new CsvMapper();
28-
File file = new ClassPathResource(fileName).getFile();
29+
InputStream is = new ClassPathResource(fileName).getInputStream();
2930
MappingIterator<T> readValues =
30-
mapper.readerFor(type).with(bootstrapSchema).readValues(file);
31+
mapper.readerFor(type).with(bootstrapSchema).readValues(is);
3132
return readValues.readAll();
3233
} catch (Exception e) {
3334
LOGGER.error("Error occurred while loading object list from file " + fileName, e);

src/main/java/com/redislabs/demos/redisbank/transactions/BankTransactionForwarder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public void afterPropertiesSet() throws Exception {
5353

5454
@Override
5555
public void onMessage(MapRecord<String, String, String> message) {
56+
LOGGER.info("Message received from stream: {}", message);
5657
// Update search index whenever a new transaction arrives via the stream
5758
String messageString = message.getValue().get("transaction");
5859
try {
@@ -64,7 +65,7 @@ public void onMessage(MapRecord<String, String, String> message) {
6465

6566
// Stream message to websocket connection topic
6667
smso.convertAndSend(config.getStomp().getTransactionsTopic(), message.getValue());
67-
LOGGER.info("Streamed: {}", messageString);
68+
LOGGER.info("Websocket message: {}", messageString);
6869

6970
}
7071

src/main/java/com/redislabs/demos/redisbank/transactions/BankTransactionGenerator.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public BankTransactionGenerator(StringRedisTemplate redis, StatefulRediSearchCon
5555
this.redis = redis;
5656
this.connection = connection;
5757
this.tsc = rcf.getCommands(TimeSeriesCommands.class);
58-
transactionSources = SerializationUtil.loadObjectList(TransactionSource.class, "transaction_sources.csv");
58+
transactionSources = SerializationUtil.loadObjectList(TransactionSource.class, "/transaction_sources.csv");
5959
random = SecureRandom.getInstance("SHA1PRNG");
6060
random.setSeed("lars".getBytes("UTF-8")); // Prime the RNG so it always generates the same pseudorandom set
6161

@@ -78,22 +78,25 @@ private void createSearchIndices() {
7878
throw new RuntimeException(e);
7979
}
8080
}
81-
LOGGER.info("Creating {} index", ACCOUNT_INDEX);
8281
commands.create(ACCOUNT_INDEX, Field.text("toAccountName").build());
82+
LOGGER.info("Created {} index", ACCOUNT_INDEX);
8383

84-
LOGGER.info("Creating {} index", SEARCH_INDEX);
8584
commands.create(SEARCH_INDEX, Field.text("description").matcher(PhoneticMatcher.English).build(),
8685
Field.text("fromAccountName").matcher(PhoneticMatcher.English).build(),
8786
Field.text("transactionType").matcher(PhoneticMatcher.English).build());
87+
LOGGER.info("Created {} index", SEARCH_INDEX);
8888
}
8989

9090
private void deleteSortedSet() {
9191
redis.delete(SORTED_SET_KEY);
92+
LOGGER.info("Deleted {} sorted set", SORTED_SET_KEY);
93+
9294
}
9395

9496
private void createTimeSeries() {
9597
redis.delete(BALANCE_TS);
9698
tsc.create(BALANCE_TS, 0);
99+
LOGGER.info("Created {} time seris", BALANCE_TS);
97100
}
98101

99102
private void createInitialStream() {
@@ -118,6 +121,7 @@ private void streamBankTransaction(BankTransaction bankTransaction) {
118121
transactionString = SerializationUtil.serializeObject(bankTransaction);
119122
update.put(TRANSACTION_KEY, transactionString);
120123
redis.opsForStream().add(TRANSACTIONS_STREAM, update);
124+
LOGGER.info("Streamed {}", transactionString);
121125
} catch (JsonProcessingException e) {
122126
LOGGER.error("Error serialising object to JSON", e.getMessage());
123127
}
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
stomp.host=localhost
22
stomp.protocol=ws
33
stomp.port=8080
4-
stomp.endpoint=/websocket
5-
stomp.destinationPrefix=/topic
6-
stomp.transactionsTopic=/topic/transactions
7-
84
spring.redis.host=localhost
95
spring.redis.port=6379
106

11-
#spring.redis.host=lars5.northeurope.redisenterprise.cache.azure.net
7+
#stomp.host=<app>-<service>.azuremicroservices.io
8+
#stomp.protocol=wss
9+
#stomp.port=443
10+
#spring.redis.host=<name>.<region>.redisenterprise.cache.azure.net
1211
#spring.redis.port=10000
13-
#spring.redis.password=RzM8a9+p2VHu6ZWVwKWyHbHZBUc1jueNWLg8uQZPe9w=
12+
#spring.redis.password=
13+
14+
stomp.endpoint=/websocket
15+
stomp.destinationPrefix=/topic
16+
stomp.transactionsTopic=/topic/transactions
17+
management.endpoints.web.exposure.include=env

src/main/resources/static/assets/js/transactions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ var transactionsOverview = new Vue({
100100
axios.get(stompConfigUrl)
101101
.then(function (response) {
102102
var stompconfig = response.data
103-
var url = 'ws://' + stompconfig.host + ':' + stompconfig.port + stompconfig.endpoint
103+
var url = stompconfig.protocol + '://' + stompconfig.host + ':' + stompconfig.port + stompconfig.endpoint
104104
this.stompClient = Stomp.client(url)
105105

106106
this.stompClient.connect(

0 commit comments

Comments
 (0)