You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Follow [Create Instance of SAP Event Mesh Service](cp-enterprisemessaging-instance-create) and follow [Create Queues and Queue Subscriptions for Event Mesh](cp-enterprisemessaging-queue-queuesubscription) to create a queue in an instance of Event Mesh.
- Follow [Create Instance of SAP Event Mesh Service](cp-enterprisemessaging-instance-create) and [Create Queues and Queue Subscriptions for Event Mesh](cp-enterprisemessaging-queue-queuesubscription) to create a queue in an instance of Event Mesh.
15
15
- Follow [Install the Cloud Foundry Command Line Interface(CLI)](cp-cf-download-cli) to download and work with CLI.
16
-
17
-
## Recommended
18
-
- Installed IDE of choice (e.g. [Visual Studio](https://code.visualstudio.com/) with installed [Java language support](https://marketplace.visualstudio.com/items?itemName=redhat.java) plug in)
16
+
- Installed IDE of choice (e.g. [Visual Studio](https://code.visualstudio.com/) with installed [Java language support](https://marketplace.visualstudio.com/items?itemName=redhat.java) plugin)
19
17
20
18
## Details
21
19
### You will learn
22
-
- How to create a basic messaging client application with Java, using combinations of vanilla Java, Spring, and JMS for sending messages to a queue
20
+
- How to create a basic messaging client application with Java
23
21
- How to deploy this application to the SAP Event Mesh and test it
24
22
25
-
26
23
---
27
24
28
-
[ACCORDION-BEGIN [Step 1: ](Setup the environment)]
- Create a `MessagingServiceFactory` object with the help of `MessagingServiceFactoryCreator` and get a `MessagingServiceJmsConnectionFactory`.
119
-
The Connection Factory can be configured with the `MessagingServiceJmsSettings`. In case the reconnection feature is not needed and an individual
120
-
connection mechanism (for example, through a connection cache) is used these settings can be skipped. The connection factory can be built with `messagingServiceFactory.createConnectionFactory(MessagingServiceJmsConnectionFactory.class,settings)`.
121
108
122
-
```
123
-
MessagingServiceJmsSettings settings = new MessagingServiceJmsSettings(); // settings are preset with default values (see JavaDoc)
124
-
settings.setMaxReconnectAttempts(5); // use -1 for unlimited attempts
3. Create a `MessagingServiceFactory` object with the help of `MessagingServiceFactoryCreator` and get a `MessagingServiceJmsConnectionFactory`.
119
+
120
+
The Connection Factory can be configured with the `MessagingServiceJmsSettings`. In case the reconnection feature is not needed and an individual connection mechanism (for example, through a connection cache) is used these settings can be skipped. The connection factory can be built with `messagingServiceFactory.createConnectionFactory(MessagingServiceJmsConnectionFactory.class,settings)`.
121
+
122
+
```
123
+
MessagingServiceJmsSettings settings = new MessagingServiceJmsSettings(); // settings are preset with default values (see JavaDoc)
124
+
settings.setMaxReconnectAttempts(5); // use -1 for unlimited attempts
[ACCORDION-BEGIN [Step 4: ](Code Snippets - Point to Point communication)]
142
-
### Sending
142
+
#### Sending
143
143
144
144
Open the `MessagingServiceRestController.java` source code. Change the value of `QUEUE_PATH` based on the values of the instance you created.
145
145
146
-
`private static final String QUEUE_PATH = "queue/{queueName}";`
146
+
`private static final String QUEUE_PATH = "queue/{queueName}";`
147
147
148
148
For sending messages a Connection and a Session are required first. Note that those resources must be closed if they are not needed anymore. As those objects
149
149
are implementing the `autoclosable` interface they will be closed automatically after the try-catch-block. Now a `BytesMessage` can be created. In the next
@@ -164,10 +164,13 @@ try (
164
164
LOG.error("Could not send message={}.", message, e);
165
165
}
166
166
```
167
-
### Receiving
168
-
In this example a consumer is listening to a queue. Again a Connection and a Session are required. Note that those resources must be closed if they are not
169
-
needed anymore. First a queue with the mandatory prefix "queue:" is bound to a consumer. Since the messages are sent as a `ByteMassage`, the message needs to be
167
+
168
+
#### Receiving
169
+
170
+
In this example, a consumer is listening to a queue. Again a Connection and a Session are required. Note that those resources must be closed if they are not
171
+
needed anymore. First, a queue with the mandatory prefix "queue:" is bound to a consumer. Since the messages are sent as a `ByteMassage`, the message needs to be
[ACCORDION-BEGIN [Step 5: ](Code Snippets - Publish and Subscribe)]
191
+
192
+
Open the `MessageingServiceRestController.java` source code. Change the value of `TOPIC_PATH` and `QUEUE_PATH` based on the values of the instance you created.
189
193
190
-
Open the `MessageingServiceRestController.java` source code. Change the value of `TOPIC_PATH` & `QUEUE_PATH` based on the values of the instance you created.
194
+
`private static final String TOPIC_PATH = "topic/{topicName}";
195
+
private static final String QUEUE_PATH = "queue/{queueName}";`
191
196
192
-
`private static final String TOPIC_PATH = "topic/{topicName}";
193
-
private static final String QUEUE_PATH = "queue/{queueName}";`
197
+
#### Sending
194
198
195
-
### Sending
196
199
For sending messages a Connection and a Session are required first. Note that those resources must be closed if they are not needed anymore. As those objects are
197
200
implementing the `autoclosable` interface they will be closed automatically after the try-catch-block. Now a `BytesMessage` can be created. In the next steps,
198
201
a topic is bound (not created) to a producer. Note, that the prefix "topic:" is mandatory. Finally, the message can be sent to the topic.
LOG.error("Could not send message={}.", message, e);
211
215
}
212
216
```
213
-
### Receiving
217
+
218
+
#### Receiving
219
+
214
220
Currently, direct topic subscription is *not supported for the default plan*. In this example, a consumer is subscribed to a specific topic. Again a Connection
215
221
and a Session are needed. Note that those resources must be closed if they are not needed anymore. First a topic (not created) with the mandatory prefix "topic:"
216
222
is bound to consumer. Since the messages are sent as a `ByteMessage` the message needs to be converted to say a String
@@ -234,10 +240,12 @@ try (
234
240
[DONE]
235
241
[ACCORDION-END]
236
242
237
-
[ACCORDION-BEGIN [Step 6: ](Build & Deploy)]
238
-
- Build the project with maven (`maven clean install`)
239
-
- Push it to Cloud Foundry via `cf push` using CLI from the folder where the executable is available.
240
-
- After successful deployment, follow [Send and Receive Test Event Mesh](cp-enterprisemessaging-test-queue-sendreceive) to test sending and receiving of message using the Java client.
243
+
[ACCORDION-BEGIN [Step 6: ](Build and deploy)]
244
+
1. Build the project with maven (`maven clean install`).
245
+
246
+
2. Push it to Cloud Foundry via `cf push` using CLI from the folder where the executable is available.
247
+
248
+
3. After successful deployment, follow [Send and Receive Test Event Mesh](cp-enterprisemessaging-test-queue-sendreceive) to test sending and receiving of message using the Java client.
0 commit comments