Example: Using the messaging system composition service
The following example shows how we might use the messaging system composition service. If you have a store named MyStore, and we want to assign two transports, e-mail and file, to the CompanyAOrderCreateMsg message type, you would: Add an entry to Struts configuration files for the JSP file to use for composing this outbound message. The keys for the Struts configuration files are the view name, the store ID, and the device format ID which can be identified from the name attribute "OrderCreateXMLFormatView/0/-3" For example, in WebSphere Commerce Version 9.0.0.x, the keys are defined as follows:
<forward className="com.ibm.commerce.struts.ECActionForward" name="OrderCreateXMLFormatView/0/-3" path="/OrderCreateXML.jsp"> <set-property property="resourceClassName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl"/> <set-property property="properties" value="storeDir=no"/> <set-property property="interfaceName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommand"/> <set-property property="implClassName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl"/> <set-property property="direct" value="true"/> </forward>
In Version 9.0.1+, they are defined this way:
<result name="OrderCreateXMLFormatView/0/-3"> <param name="location">/OrderCreateXML.jsp</param> <param name="properties">storeDir=no</param> <param name="implClassName">com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl</param> <param name="interfaceName">com.ibm.commerce.messaging.viewcommands.MessagingViewCommand</param> <param name="resourceClassName">com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl</param> <param name="direct">true</param> </result>
Important: Each view created to be used by the Messaging System's compose service must use the Messaging View Command for the interface and class name fields. It must also contain the name of the JSP file and any sub-directory relative to the Stores.war and store directory in the path field. To summarize:
- INTERFACENAME
- com.ibm.commerce.messaging.viewcommands.MessagingViewCommand
- CLASSNAME
- com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl
- PATH
- The parameter containing the JSP file name pre-pended with any sub-directory relative to the store directory.
- PROPERTIES
- Use the following format to point to the JSP file docname=jsp file.
Note: In the struts configuration, PROPERTIES is optional and needed if and only if the value is "storeDir=no". This property is needed if the jsp is located at the default Stores.war directory.
- DEVICEFMT_ID
- Represents the device format and should use the value -3 (the standard device format) unless using custom device formats for our application. The DEVICEFMT_ID must correspond to the device format selected when assigning a message type to a transport.
In the following example the MyStore STOREENT_ID is 10001 and the viewname is CompanyAOrderAuthorizedView. To avoid possible migration problems, ensure that you prefix the both the view name and the message type name with a unique prefix. In the name attribute, "CompanyAOrderAuthorizedView/10001/-3" represents viewname, store ID and device format ID respectively.
In Version 9.0.0.x, the code is as follows:
<forward className="com.ibm.commerce.struts.ECActionForward" name="CompanyAOrderAuthorizedView/10001/-3" path="/Store_10001_Dir/OrderCreateXML.jsp"> <set-property property="resourceClassName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl"/> <set-property property="interfaceName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommand"/> <set-property property="implClassName" value="com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl"/> <set-property property="direct" value="true"/> </forward>
In Version 9.0.1+, it is:
<result name="CompanyAOrderAuthorizedView/10001/-3"> <param name="location">/Store_10001_Dir/OrderCreateXML.jsp</param> <param name="implClassName">com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl</param> <param name="interfaceName">com.ibm.commerce.messaging.viewcommands.MessagingViewCommand</param> <param name="resourceClassName">com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl</param> <param name="direct">true</param> </result>
Use the Administration Console to assign the e-mail and file transports to the CompanyAOrderCreateMsg message and configure the settings. This can be done using either site or store level administration authority. Creating settings on site level will make it accessible to all stores.
In the implementation of a command, instantiate the SendMsgCmd command to use messaging services and call the setMsgType() and setStoreID() methods, using the message type name of the CompanyAOrderCreateMsg message type and the store ID of storeent_id of 10001. Place the CompanyAOrderCreateMsg.jsp file in the store's root directory.
To use site-level configuration, do the following:
- Specify the STOREENT_ID as 0.
- Add PROPERTIES of storeDir=no to the JSP file name.
- Place the JSP file in the WC_eardir/Stores.war directory.
- Invoke the compose method of the outbound messaging system interface and pass any additional parameters in the form of a TypedProperty object. Refer to the topic Message content setting services.
- Call sendImediate or sendTransacted on SendMsgCmd if we want the message to be sent immediately or after the transaction has successfully been committed. Refer to the Messaging System documentation for a further explanation of the use of each method.
- Call execute method of the SendMsgCmd to execute sending.
Related concepts
Outbound messaging system
Related tasks
Configure a transport method for the site
Encoding for e-mail transmission
Related reference
Outbound messages