AMC - ABAP Messaging Channels
ABAP Messaging Channels (AMC) are a method of communication between ABAP programs using messages. Using a publish-and-subscribe mechanism, messages can be exchanged between any AS ABAP programs, including communication between different user sessions and AS Instances. Data objects with specific data types are allowed as messages. Messages that can be sent and received are:
- Text strings
- Byte strings
- Content that can be serialized in accordance with fixed protocols. Helper classes are available for serializations and deserializations.
ABAP Messaging Channels are implemented as repository objects that can be accessed in sender and receiver programs using an interface-based an class-based programming interface (API). The classes and interfaces of the API use the naming convention CL_AMC_... and IF_AMC_... respectively. . Communication between different AS Instances takes places across the message server.
7.31 | 7.40 | 7.54
- Any data object can be sent by being serialized in a suitable way by the sender and deserialized by the receiver. Possible formats include XML or JSON in strings or SAP's own Push Channel Protocol.
- The sendable messages The length of messages that can be sent is currently restricted to approximately 1 MB. Character strings are converted to the UTF-8 format. The limit can be increased by changing the profile parameter rdisp/long_messages/max_length.
Messaging Channels as Repository Objects
An ABAP Messaging Channel defined as a repository object must exist for each AMC communication. An ABAP Messaging Channel like this can be created in Repository Browser in ABAP Workbench by opening the context menu of a package and choosing Connectivity. Connectivity Browser in Object Navigator provides another means of access. To open Object Navigator for AMCs, use transaction SAMC.
An ABAP Messaging Channel is identified by its assignment to an application and by its name. The name must start with a forward slash character (/) and is not case-sensitive. The following properties can be defined for an ABAP Messaging Channel:
- Message type
- TEXT for text strings
- BINARY for byte strings
- PCP for SAP's own Push Channel Protocol (PCP)
- Authorized programs
- Send, which authorizes the program to send AMC messages
- Receive, which authorizes the program to receive AMC messages
- Bind APC WebSocket as consumer, which authorizes the program (usually the class pool of an APC handler class) to bind its WebSocket connection to an ABAP Messaging Channel. This makes the APC connection partners (such as Web browsers) into AMC consumers.
See the messaging channels /demo_text and /demo_binary of the application DEMO_AMC in the package SABAPDEMOS.
Sending AMC Messages
Before an AMC message can be sent in an authorized program (known as the publish part), the factory method CREATE_MESSAGE_PRODUCER of the system class CL_AMC_CHANNEL_MANAGER must be used to create a sender object for a messaging channel from the repository. The application and name of the channel are passed here. The returned reference variable of type IF_AMC_MESSAGE_PRODUCER must be cast to a type-specific interface that contains a method SEND used to send type-friendly messages. The following interfaces are possible, depending on the type of messaging channel used:
- The sender of an AMC message implements the publish part of the publish-and-subscribe mechanism in AMC. The sender does not usually know whether receivers are registered for the AMC message.
- The parameter I_SUPPRESS_ECHO of the method CREATE_MESSAGE_PRODUCER can be used to specify whether messages are sent to the current ABAP session or not. It may be helpful to suppress messages like these when joining AMC with APC to stop superfluous messages from being sent.
Receiving AMC Messages
Before an AMC message can be received in an authorized program (known as the subscribe part), the factory method CREATE_MESSAGE_CONSUMER of the system class CL_AMC_CHANNEL_MANAGER must be used to create a consumer for a messaging channel from the repository. The application and name of the channel are passed here. The returned reference variable has the type IF_AMC_MESSAGE_CONSUMER. The consumer methods START_MESSAGE_DELIVERY and STOP_MESSAGE_DELIVERY have two tasks:
- Definition of the AMC delivery phase
- Registration of the receiver objects for messaging channel messages
Once one or more receiver objects have been registered, the statement WAIT FOR MESSAGING CHANNELS can be used to put the program in a wait state where it is ready to receive the messages. If, while the program is waiting, a message is received through a messaging channel for which a receiver object is registered, the associated RECEIVE method is executed and a check is made to see whether a logical condition is true or false. The wait state is persisted as long as the condition is false (but a maximum duration can be configured). In this way, multiple messages can be consumed until a message is received that ends the wait state.
- The methods START_MESSAGE_DELIVERY and STOP_MESSAGE_DELIVERY both cause a database commit.
- It is not possible to receive AMC messages during the update process.
Alongside the publish-and-subscribe mechanism, where the sender of message does not know the receivers, AMC also provides point-to-point communication, where a sender can create an AMC message for a specific receiver. The ID of the receiver session is required here.
- A receiver can use the static method GET_CONSUMER_SESSION_ID of the class CL_AMC_CHANNEL_MANAGER to get the ID of its session and pass it to the sender in an appropriate way.
- A sender that knows the ID of a receiver session can use the factory method CREATE_MESSAGE_PRODUCER_BY_ID of the class CL_AMC_CHANNEL_MANAGER to create a special sender object for point-to-point communication for this receiver session. An AMC message sent using an object like this is only processed by the receiver of the receiver session passed to the parameter I_CONSUMER_SESSION_ID.
The parameter I_COMMUNICATION_TYPE of the method CREATE_MESSAGE_PRODUCER_BY_ID can be used to configure whether a message is sent synchronously or asynchronously, with the latter the default. When a message is sent synchronously, the sender waits for confirmation that the message was passed to the receiver session. It raises an exception if this is not the case.
The executable example Receiving AMC Messages displays the ID of the receiver session. If this ID is entered in the example Sending AMC Messages, the message is sent synchronously and to this receiver session only.
AMC - Security
Access to an ABAP Messaging Channel is controlled by specifying the authorized programs and their activities. When binding an APC WebSocket and when receiving using an APC WebSocket as a consumer, it is also possible to specify a virus scan profile to be used for the check performed by the virus scan interface (VSI).
AMC - Exceptions
Error situations in sender and receiver programs (such as violations of rules set by the properties of a messaging channel) raise exceptions of the class CX_AMC_ERROR.
AMC - Test and Analysis
AMC messages are both sent and received in AS ABAP, which means that existing test and analysis tools, such as ABAP Debugger, runtime analysis, or performance trace can be used as previously. There is also a special AMC logger:
- The transaction AMC_LOG_ADMIN can be used to switch AMC logging on and off for specific ABAP Messaging Channels.
- The transaction AMC_LOG_PROCESSING can be used to manage the AMC log entries.
The transaction SMAMC provides an overview of all ABAP Messaging Channels for which AMC consumers are registered.
Detailed information about AMC can be found in the ABAP Channels documentation in SAP Help Portal.