Skip to content

Commit 3a2b861

Browse files
committed
Automatic commit: Move 'cp-enterprisemessaging-javaclient-app' from QA to Production
1 parent 9c0865c commit 3a2b861

1 file changed

Lines changed: 67 additions & 59 deletions

File tree

tutorials/cp-enterprisemessaging-javaclient-app/cp-enterprisemessaging-javaclient-app.md

Lines changed: 67 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
---
2-
title: Create an Application for Sending and Receiving Messages using Java based client
3-
description: Develop and deploy a basic Java based messaging application for sending and receiving messages to a queue.
2+
title: Create App for Sending and Receiving Messages Using a Java-Based Client
3+
description: Develop and deploy a basic Java-based messaging application for sending and receiving messages to a queue.
44
time: 45
55
auto_validation: true
66
tags: [ tutorial>intermediate, topic>java, products>sap-business-technology-platform, tutorial>license]
77
primary_tag: products>sap-event-mesh
88
---
99

1010
## Prerequisites
11-
- Installed Java 8 -> [Java download](https://www.java.com/en/download/)
12-
- Installed Maven 3.x -> [Maven download](https://maven.apache.org/download.cgi)
13-
- Installed Git -> [Git download](https://git-scm.com/downloads)
14-
- 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.
11+
- Installed Java 8: [Java download](https://www.java.com/en/download/)
12+
- Installed Maven 3.x: [Maven download](https://maven.apache.org/download.cgi)
13+
- Installed Git: [Git download](https://git-scm.com/downloads)
14+
- 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.
1515
- 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)
1917

2018
## Details
2119
### 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
2321
- How to deploy this application to the SAP Event Mesh and test it
2422

25-
2623
---
2724

28-
[ACCORDION-BEGIN [Step 1: ](Setup the environment)]
25+
[ACCORDION-BEGIN [Step 1: ](Set up environment)]
2926

3027

3128
| Application | Scenario Description
@@ -50,11 +47,11 @@ primary_tag: products>sap-event-mesh
5047
| | The REST endpoints are provided via the
5148
| | `MessagingServiceRestController`.
5249

53-
To download and install the samples, just clone the repository via:
54-
[git clone](https://github.com/SAP/enterprise-messaging-client-java-samples)
50+
To download and install the samples, just clone the repository via: [git clone](https://github.com/SAP/enterprise-messaging-client-java-samples)
5551

5652
This downloads both the scenarios to your local IDE and the structure is as follows:
57-
![Project Structure](ProjectStructure.JPG)
53+
54+
!![Project Structure](ProjectStructure.JPG)
5855

5956
The downloaded project has all the dependencies and required client files for both scenarios mentioned above.
6057
The Event Mesh service descriptor is `/config/em-config-default.json`. Detailed information on different parameters of the
@@ -98,52 +95,55 @@ To be able to build, deploy and run the Java message client, ensure the followin
9895

9996
[ACCORDION-BEGIN [Step 3: ](Code Snippets - common for both examples)]
10097

101-
Open the manifest.yml file for the projects and make changes to the following parameters:
102-
- applications:
103-
`-` name: *<<Customized name of choice. Should be unique for a space of SCP>>*
104-
- services:
105-
`-` *<<name of the SAP Event Mesh instance>>*
98+
1. Open the `manifest.yml` file for the projects and make changes to the following parameters:
10699

100+
- applications:
107101

108-
- Get the `MessagingService`
102+
`-` name: *<<Customized name of choice. Should be unique for a space of SCP>>*
109103

110-
```
111-
ServiceConnectorConfig config = null; // currently there are no configurations for the MessagingServiceFactory supported
112-
Cloud cloud = new CloudFactory().getCloud();
113-
// get a messaging service factory via the service connector
114-
MessagingService messagingService = cloud.getSingletonServiceConnector(MessagingService.class, config);
104+
- services:
115105

116-
```
106+
`-` *<<name of the SAP Event Mesh instance>>*
117107

118-
- 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)`.
121108

122-
```
123-
MessagingServiceJmsSettings settings = new MessagingServiceJmsSettings(); // settings are preset with default values (see JavaDoc)
124-
settings.setMaxReconnectAttempts(5); // use -1 for unlimited attempts
125-
settings.setInitialReconnectDelay(3000);
126-
settings.setReconnectDelay(3000);
127-
MessagingServiceFactory messagingServiceFactory = MessagingServiceFactoryCreator.createFactory(messagingService);
128-
MessagingServiceJmsConnectionFactory connectionFactory = messagingServiceFactory.createConnectionFactory(MessagingServiceJmsConnectionFactory.class, settings)
109+
2. Get the `MessagingService`
129110

130-
```
131-
- Create a connection and a session
111+
```
112+
ServiceConnectorConfig config = null; // currently there are no configurations for the MessagingServiceFactory supported
113+
Cloud cloud = new CloudFactory().getCloud();
114+
// get a messaging service factory via the service connector
115+
MessagingService messagingService = cloud.getSingletonServiceConnector(MessagingService.class, config);
116+
```
132117
133-
```
134-
Connection connection = connectionFactory.createConnection();
135-
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
136-
```
118+
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
125+
settings.setInitialReconnectDelay(3000);
126+
settings.setReconnectDelay(3000);
127+
MessagingServiceFactory messagingServiceFactory = MessagingServiceFactoryCreator.createFactory(messagingService);
128+
MessagingServiceJmsConnectionFactory connectionFactory = messagingServiceFactory.createConnectionFactory(MessagingServiceJmsConnectionFactory.class, settings)
129+
```
130+
131+
4. Create a connection and a session
132+
133+
```
134+
Connection connection = connectionFactory.createConnection();
135+
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
136+
```
137137
138138
[DONE]
139139
[ACCORDION-END]
140140
141141
[ACCORDION-BEGIN [Step 4: ](Code Snippets - Point to Point communication)]
142-
### Sending
142+
#### Sending
143143
144144
Open the `MessagingServiceRestController.java` source code. Change the value of `QUEUE_PATH` based on the values of the instance you created.
145145
146-
`private static final String QUEUE_PATH = "queue/{queueName}";`
146+
`private static final String QUEUE_PATH = "queue/{queueName}";`
147147
148148
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
149149
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 (
164164
LOG.error("Could not send message={}.", message, e);
165165
}
166166
```
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
170172
converted to say a String.
173+
171174
```
172175
try (Connection connection = connectionFactory.createConnection();Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
173176
connection.start();
@@ -179,23 +182,24 @@ try (Connection connection = connectionFactory.createConnection();Session sessio
179182
} catch (JMSException e) {
180183
LOG.error("Could not receive message.", e);
181184
}
182-
183185
```
184186
185187
[DONE]
186188
[ACCORDION-END]
187189
188-
[ACCORDION-BEGIN [Step 5: ](Code Snippets - Publish & Subscribe)]
190+
[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.
189193
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}";`
191196
192-
`private static final String TOPIC_PATH = "topic/{topicName}";
193-
private static final String QUEUE_PATH = "queue/{queueName}";`
197+
#### Sending
194198
195-
### Sending
196199
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
197200
implementing the `autoclosable` interface they will be closed automatically after the try-catch-block. Now a `BytesMessage` can be created. In the next steps,
198201
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.
202+
199203
```
200204
try (
201205
Connection connection = connectionFactory.createConnection();
@@ -210,7 +214,9 @@ try (
210214
LOG.error("Could not send message={}.", message, e);
211215
}
212216
```
213-
### Receiving
217+
218+
#### Receiving
219+
214220
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
215221
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:"
216222
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 (
234240
[DONE]
235241
[ACCORDION-END]
236242
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.
241249
242250
[VALIDATE_2]
243251
[ACCORDION-END]

0 commit comments

Comments
 (0)