Using SAP Enterprise Messaging To Bridge The World of Sync and Async
Using SAP Enterprise Messaging To Bridge The World of Sync and Async
Exercises / Solutions
Speakers Name / Company
Las Vegas
Oliver Liemert / SAP SE
Tobias Griebe / SAP SE
Bangalore
Balakrishna Gottipati / SAP SE
Soumya Dey / SAP SE
Barcelona
Balakrishna Gottipati / SAP SE
Martin Bachmann / SEP SE
CPL162
TABLE OF CONTENTS
INTRODUCTION ..................................................................................................................................................... 3
BENEFITS ............................................................................................................................................................... 3
HANDS-ON SCENARIO ......................................................................................................................................... 3
GETTING STARTED ............................................................................................................................................... 4
CREATE INITIAL MESSAGING APPLICATION .................................................................................................... 5
DEPLOY AND CONFIGURE MESSAGING APPLICATION ON SAP CLOUD PLATFORM .............................. 19
CONFIGURE & TEST GITHUB WEBHOOK ........................................................................................................ 27
OPTIONAL: CHECK LOG ENTRIES .................................................................................................................... 32
CREATE SAP HANA DATABASE TABLE .......................................................................................................... 35
ENHANCE MESSAGING APPLICATION TO CONSUME MESSAGES FROM MESSAGING QUEUE............. 40
VERIFY END 2 END FLOW: GITHUB WEBHOOK TO SAP HANA DATABASE .............................................. 48
2
CPL162
INTRODUCTION
In the Hands-on session CPL162, you will get a better understanding of the SAP Enterprise Messaging service.
SAP Enterprise Messaging is a cloud-based messaging framework that enables you to connect applications,
services, and devices across different technologies, platforms, and clouds.
Scaling to millions of messages per second in real-time, you can send and receive messages reliably using open
standards and protocols. You can decouple application logic, develop microservices, and support event-driven
architectures.
BENEFITS
Fire-and-Forget Asynchronous Communication
You can free applications from the ties of synchronous communication using enterprise messaging service.
Heterogeneous Integration
You can connect different technology platforms using Java apps and SAP Enterprise Messaging service.
HANDS-ON SCENARIO
In the course of this hands-on exercise you will be creating a simple messaging application. This will provide an
endpoint to be configured with GitHub’s webhook API. Every commit to be done on the configured GitHub
repository will be received in the SAP Cloud Platform, parsed and stored in a message queue provided by the
SAP Enterprise Messaging service. The scenario will be enhanced to asynchronously consume the messages out
of the queue and store them into a database table in the SAP Cloud Platform. You will use Eclipse to develop the
messaging application, implemented in Java. The application will be deployed from the SAP Cloud Platform
Cockpit and the SAP HANA Web-based Development Workbench will be used to create the needed database
tables.
3
CPL162
GETTING STARTED
In order to log on to the notebooks during the hands-on session you have to use the following user:
User: FAIR\student
Password: Welcome17
Each group will be provided with a temporary SAP Cloud Platform account. The accounts will be used to run the
messaging applications with the needed SAP Enterprise Messaging capabilities. Details will be handed out by
the presenter.
Please note that the provided accounts are meant to be used for the CPL162 hands-on session only. The
accounts will be deleted after the TechEd 2017 event.
4
CPL162
Overview
Estimated time: 20 minutes
Objective
The objective of this chapter is to implement and package the initial messaging java application, which is the
basis for the second chapter. The implementation will be done using Eclipse.
Exercise Description
You will use Eclipse to create a new Dynamic Web Project. Next you will adopt the build- and runtime-
dependencies and implement the java application based on a servlet. Finally, the project will be exported so it
can be deployed to the SAP Cloud Platform in the next step.
Explanation Screenshot
Eclipse is starting.
5
CPL162
Explanation Screenshot
Click on Next.
Click on Finish.
6
CPL162
Explanation Screenshot
\\students.fair.sap.corp\Studentshare\
CPL162\lib\javax.servlet-api-3.0.1.jar
\\students.fair.sap.corp\Studentshare\
CPL162\lib\slf4j-api-1.7.25.jar
7
CPL162
Explanation Screenshot
8
CPL162
Explanation Screenshot
9
CPL162
Explanation Screenshot
14. Provide
Java package:
com.sap.teched.cpl162_##
Class Name:
GithubWebhookServlet
Click on Next.
10
CPL162
Explanation Screenshot
11
CPL162
Explanation Screenshot
21. Replace the <queue name> with the private static final String QUEUE_NAME =<queue name>;
string "cpl162_##". This defines the
message queue that will be used to
exchange messages. The information is private static final String QUEUE_NAME = "cpl162_00";
needed in one of the coming steps of
this exercise.
12
CPL162
Explanation Screenshot
23. The doPost is called by the server (via protected void doPost(HttpServletRequest request,
the service method) to allow a servlet to HttpServletResponse response) throws ServletException,
handle a POST request. The HTTP IOException {
POST method allows the client to send
data of unlimited length to the Web response.setContentType("application/json");
server a single time. PrintWriter responseWriter = response.getWriter();
The payload is parsed, as not all // Parse GitHub push event into an Object
information send by GitHub is used in CommitLog commitLog =
this exercise. gitHubEventParser.parsePushEvent(json);
13
CPL162
Explanation Screenshot
Click Finish.
14
CPL162
Explanation Screenshot
15
CPL162
Explanation Screenshot
javax.jms.Message
javax.jms.Connection
org.slf4j.Logger
javax.jms.Queue
javax.jms.Session
Click Finish.
Click Finish.
16
CPL162
Explanation Screenshot
17
CPL162
Explanation Screenshot
37. Provide
D:\Files\Session\CPL162\
CPL162_messaging_##.war
Click on Finish.
Summary
Using Eclipse, you have now created an application that can receive incoming messages on the /webhook
endpoint, transform and send those messages to a queue on the messaging host. The application has been
exported so it can be deployed to the SAP Cloud Platform in the next step.
You are now able to:
• Create a simple SAP Enterprise Messaging implementation using Eclipse
• Configure the needed library dependencies for build- and runtime
• Export the application for deployment on SAP Cloud Platform
18
CPL162
Overview
Estimated time: 15 minutes
Objective
The objective of this chapter is to deploy and configure the previously created java messaging application on the
SAP Cloud Platform. Once the configuration is completed you will run the same and check the successful
execution.
Exercise Description
You will log on to the SAP Cloud Platform with the user handed out by the presenter. You will have access to a
SAP Cloud Platform account that has the SAP Cloud Platform Enterprise Messaging service already enabled.
After deploying your application, it needs to be bound to the messaging host. You will initially test the servlet with
a simple call from the browser.
19
CPL162
Explanation Screenshot
20
CPL162
Explanation Screenshot
21
CPL162
Explanation Screenshot
22
CPL162
Explanation Screenshot
Click on Deploy.
23
CPL162
Explanation Screenshot
24
CPL162
Explanation Screenshot
Click to create
a new queue.
16. Provide
Click on Save.
25
CPL162
Explanation Screenshot
Summary
You have now deployed your messaging application on the SAP Cloud Platform and bound the same to the SAP
Enterprise Messaging host. Furthermore, you have defined the queue that is holding the messages.
You are now able to:
• Logon to SAP Cloud Platform and deploy messaging application
• Bind application to messaging host
• Define queue on messaging host
26
CPL162
Overview
Estimated time: 10 minutes
Objective
The objective of this chapter is to do the necessary configuration on GitHub in order to connect to the SAP Cloud
Platform application created in the previous steps. At the end of this chapter you will receive new messages
inside the defined queue for each new commit on the GitHub repository.
Exercise Description
You will logon to GitHub, create a new repository or re-use an existing repository. In the setting of this repository
the webhook endpoint of the SAP Cloud Platform application will be provided. Webhooks allow external services
to be notified when certain events happen within your repository. When the specified events happen, we’ll send
a POST request to each of the URLs you provide. At the end you will commit changes to the GitHub repository
and you will check, that these events will create messages in the defined messaging queue.
Explanation Screenshot
27
CPL162
Explanation Screenshot
Click on Settings.
28
CPL162
Explanation Screenshot
29
CPL162
Explanation Screenshot
30
CPL162
Explanation Screenshot
Summary
You have now configured the GitHub repository to send events to the webhook exposed by the previously
created SAP Cloud Platform application. The success can be seen by the messages in the messaging queue.
31
CPL162
Overview
Estimated time: 5 minutes
Objective
The objective of this chapter is to configure the logging mechanism for your SAP Cloud Platform application
Exercise Description
You will change the logging setting for your java application. Specific loggers will be set to DEBUG mode, to see
the logs written by your implementation.
32
CPL162
Explanation Screenshot
Click Set.
Click Close.
33
CPL162
Explanation Screenshot
Summary
You have configured the logs to show debug information, to verify that your messaging application is working
properly.
You are now able to:
• Configure logs on SAP Cloud Platform
• Verify a SAP Enterprise Messaging application is working properly
34
CPL162
Overview
Estimated time: 10 minutes
Objective
The objective of this chapter is to create a table on the SAP HANA database. The database will be bound to the
java application, so it can be used during runtime.
Exercise Description
You will use the SAP HANA Web-based Development Workbench to create a new table on the SAP HANA
database. This table will be used to store the messages being sent to the messaging queue. This chapter will be
completed by checking the content of the table and binding the database to your java application, so it can be
accessed during runtime.
Explanation Screenshot
35
CPL162
Explanation Screenshot
3. Provide
password: Welcome2TechEd17
36
CPL162
Explanation Screenshot
Right-click on the
GITHUB_PUSH_LOG table and
select Open Content from the menu.
37
CPL162
Explanation Screenshot
38
CPL162
Explanation Screenshot
Click Save.
Summary
Using the SAP HANA Web-based Development Workbench you have created a new table on the database via
SQL script. You know how to check the content of the table and how to bind the database to your java
application.
39
CPL162
Overview
Estimated time: 20 minutes
Objective
The objective of this chapter is to enhance the existing messaging application to consume the messages from
the queue and store them into the table inside the HANA database.
Exercise Description
You will enhance the implementation of the messaging application. In Eclipse you will add classes that provide
the capabilities to consume messages from the messaging queue, transform them to store them in the SAP
HANA database via SQL insert.
Explanation Screenshot
messagePublisher =
new MessagePublisher
(jmsConnectionFactory);
and before
} catch (Exception e) {
inside GithubWebhookServlet.java
class.
40
CPL162
Explanation Screenshot
java.sql.Connection
org.slf4j.Logger
javax.sql.DataSource
Click Finish.
41
CPL162
Explanation Screenshot
5. Let’s have a closer look at the public void insertInDb(CommitLog commitLog) throws
implementation of SQLException, NamingException {
CommitLogDao.java:
Connection connection = datasource.getConnection();
The datasource (in this case the
connection to the HANA database) is try {
passed during initialization of the PreparedStatement pstmt =
object. connection.prepareStatement("INSERT INTO
GITHUB_PUSH_LOG (MSG, COMMITTED_ON, COMMITTER)
An SQL statement is prepared to insert VALUES (?, ?, ?)");
the details sent by the GitHub webhook pstmt.setString(1, commitLog.getMessage());
event into the HANA database. pstmt.setString(2, commitLog.getTimestamp());
pstmt.setString(3, commitLog.getCommitter());
The values will be inserted in a table pstmt.executeUpdate();
called GITHUB_PUSH_LOG. LOG.debug("Record inserted in database: {}", commitLog);
} finally {
if (connection != null) {
connection.close();
}
}
}
42
CPL162
Explanation Screenshot
javax.jms.Message
javax.jms.Connection
org.slf4j.Logger
javax.jms.Queue
javax.jms.TextMessage
javax.jms.Session
Click Finish.
commitLogDao.insertInDb(commitLog);
} catch (Exception e) {
LOG.error("Unexpected exception", e);
}
}
});
43
CPL162
Explanation Screenshot
9. Select the
GithubWebhookServlet.java tab
again in the editor pane.
Click Finish.
44
CPL162
Explanation Screenshot
12. Provide
D:\Files\Session\CPL162\
CPL162_messaging_##.war
Click on Finish.
45
CPL162
Explanation Screenshot
Click on Update.
Click Done.
46
CPL162
Explanation Screenshot
Summary
Using Eclipse, you have enhanced the messaging application to consume messages from a queue on the
messaging host. The application has been updated on the SAP Cloud Platform and has been restarted.
47
CPL162
Overview
Estimated time: 10 minutes
Objective
The objective of this chapter is to test the scenario end to end: Commit changes on GitHub and store the
information inside the SAP HANA database.
Exercise Description
You will commit changes on the configured GitHub repository and verify that messages are stored in the SAP
HANA database by using the SAP HANA Web-based Development Workbench.
Explanation Screenshot
48
CPL162
Explanation Screenshot
Click Set.
Click Close.
49
CPL162
Explanation Screenshot
Summary
Using the SAP HANA Web-based Development Workbench, as well as the logging entries, you have verified
that GitHub events are stored inside the SAP HANA database.
50
www.sap.com/contactsap
The information contained herein may be changed without prior notice. Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors.
National product specifications may vary.
These materials are provided by SAP SE or an SAP affiliate company for informational purposes only, without representation or warranty of any kind, and SAP or its affiliated companies shall not be liable
for errors or omissions with respect to the materials. The only warranties for SAP or SAP affiliate company products and services are those that are set forth in the express warranty statements
accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any course of business outlined in this document or any related presentation, or to develop or release any functionality
mentioned therein. This document, or any related presentation, and SAP SE’s or its affiliated companies’ strategy and possible future developments, products, and/or platform directions and functionality are
all subject to change and may be changed by SAP SE or its affiliated companies at any time for any reason without notice. The information in this document is not a commitment, promise, or legal obligation
to deliver any material, code, or functionality. All forward-looking statements are subject to various risks and uncertainties that could cause actual results to differ materially from expectations. Readers are
cautioned not to place undue reliance on these forward-looking statements, and they should not be relied upon in making purchasing decisions.
SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other
countries. All other product and service names mentioned are the trademarks of their respective companies. See http://www.sap.com/corporate-en/legal/copyright/index.epx for additional trademark
information and notices.