Skip to content
Samples based on the Java messaging client for Enterprise Messaging in SAP Cloud Platform.
Java HTML
Branch: master
Clone or download

Latest commit

Latest commit 37f8d85 Jan 11, 2020

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
emjapi-samples-jms-p2p
emjapi-samples-jms-pubsub
.gitignore
CREDITS.txt
LICENSE
NOTICE Rename NOTICE.txt to NOTICE Jan 10, 2020
README.adoc
pom.xml updated emjapi samples documentation Sep 10, 2019

README.adoc

Messaging Client Java - Samples for Enterprise Messaging

Description

SAP Cloud Platform Enterprise Messaging provides a cloud-based messaging framework for the development of decoupled and resilient services and integration flows (using SAP Cloud Integration) to support asynchronous communication principles. Direct integration with SAP S/4HANA Business Event Handling allows efficient development of innovative and scaling extensions.

This sample demonstrates Enterprise Messaging with Java, using combinations of vanilla Java, Spring, and JMS. Details on each sample application and the covered scenario are described in the table List of sample projects below.

For more details of SAP Cloud Platform Enterprise Messaging take a look at the SAP Cloud Platform Enterprise Messaging on SAP Help portal.

Requirements

Below requirements are necessary for each of the samples. Further necessary configuration and settings are dependent on the specific sample and are documented within each sample project.

  • Installed Java 8Java download

  • Installed GitGit download

  • Installed Maven 3.xMaven download

  • A SAP CP Account with Enterprise Messaging Service is required.
    For more detailed information and help on how to start with SAP Cloud Platform Enterprise Messaging please check the SAP help page.

    • Optional: Installed CloudFoundry CLIInstalling the cf CLI

      • This must be also fully configured with the corresponding Cloud Foundry landscape to be able to do a cf push

    • Created Enterprise Messaging Instance

      • e.g. via cli: cf cs enterprise-messaging default emjapi-samples-sapcp -c <contents of default descriptor>

      • The Service Descriptors can be found here

      • Remember to adjust the manifest file of the application

      • Include the ability to create required queues (e.g. NameOfQueue) and queue subscriptions (e.g. NameOfTopic) via e.g. MM API, UI

List of sample projects

Application Scenario Scenario Description

emjapi-samples-jms-p2p

Application for Enterprise Messaging based on Spring Web running on SAP Cloud Platform (@ CloudFoundry (with Enterprise Messaging Service)).

This sample demonstrates how messages can be send and received from a SAP CP deployed application. Therefore the messaging sample provides a Spring Boot based application which provides REST endpoints for send and receive messages via a queue (or queues) of choice. The REST endpoints are provided via the MessagingServiceRestController.

emjapi-samples-jms-pubsub

Application for Enterprise Messaging based on Spring Web running on SAP Cloud Platform (@ CloudFoundry (with Enterprise Messaging Service)).

This sample demonstrates how messages can be send and received from a topic from a SAP CP deployed application. Therefore the messaging sample provides a Spring Boot based application which provides REST endpoints for send and receive messages via a topic of choice. It also offers a REST endpoint to receive a message from a queue. The REST endpoints are provided via the MessagingServiceRestController.

Download and Installation

To download and install the samples just clone this repository via:

git clone https://github.com/SAP/enterprise-messaging-client-java-samples

For details on how to configure and run the samples please take a look into the README in the corresponding samples directory.

Usage of the client

This section describes the usage of the client without any sample application. It is described which dependencies are needed and how a MessagingServiceJmsConnectionFactory is received in a short way.

Dependencies

Three different dependencies are needed:

  1. the enterprise-messaging spring service connector which provides the MessagingService

  2. the enterprise-messaging core which creates the connection factory

  3. the enterprise-messaging JMS extension which provides the MessagingServiceJmsConnectionFactory

<dependency>
	<groupId>com.sap.cloud.servicesdk.xbem</groupId>
	<artifactId>emjapi-connector-sap-cp</artifactId>
	<version>${version.xbem.client}</version>
</dependency>

<dependency>
	<groupId>com.sap.cloud.servicesdk.xbem</groupId>
	<artifactId>emjapi-core</artifactId>
	<version>${version.xbem.client}</version>
</dependency>

<dependency>
	<groupId>com.sap.cloud.servicesdk.xbem</groupId>
	<artifactId>emjapi-extension-sap-cp-jms</artifactId>
	<version>${version.xbem.client}</version>
</dependency>

Code snippets

Get the MessagingService via the spring Cloud object

ServiceConnectorConfig config = null; // currently there are no configurations for the MessagingServiceFactory supported
Cloud cloud = new CloudFactory().getCloud();
// get a messaging service factory via the service connector
MessagingService messagingService = cloud.getSingletonServiceConnector(MessagingService.class, config);

Create a the MessagingServiceFactory object with the help of the MessagingServiceFactoryCreator and get a MessagingServiceJmsConnectionFactory. The Connection Factory can be configured with the MessagingServiceJmsSettings. In case the reconnection feature is not needed and an individual connection mechanism (e.G. through a connection cache) is used the settings can be skipped. The connection factory can be built with messagingServiceFactory.createConnectionFactory(MessagingServiceJmsConnectionFactory.class,settings).

MessagingServiceJmsSettings settings = new MessagingServiceJmsSettings(); // settings are preset with default values (see JavaDoc)
settings.setMaxReconnectAttempts(5); // use -1 for unlimited attempts
settings.setInitialReconnectDelay(3000);
settings.setReconnectDelay(3000);
MessagingServiceFactory messagingServiceFactory = MessagingServiceFactoryCreator.createFactory(messagingService);
MessagingServiceJmsConnectionFactory connectionFactory = messagingServiceFactory.createConnectionFactory(MessagingServiceJmsConnectionFactory.class, settings)

Further the MessagingServiceJmsConnectionFactory is used to create a connection and a session.

Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE));

Messaging Management API

The messaging management api (MM API) provides functionality for creating, deleting and updating queues and queue subscriptions. Further more it provides APIs to get information on queues and queue subscriptions. The MM API documentation can be found here. The MM APIs have to be enabled in the service descriptor. A description for enabling the MM API can be found here.

Creation of queues with the UI

Queues can be created through the SAP Cloud Platform Cockpit UI. More information regarding the creation of queues through the UI can be found here

Service Descriptor

Examples for the different service descriptors can be found here on the help site and in the config folder of this project.

Support

This project is 'as-is' with no support, no changes being made.
You are welcome to make changes to improve it but we are not available for questions or support of any kind.

License

Copyright (c) 2018 SAP SE or an SAP affiliate company. All rights reserved.
This file is licensed under the SAP SAMPLE CODE LICENSE AGREEMENT, v1.0-071618 except as noted otherwise in the LICENSE file.

You can’t perform that action at this time.