The following example shows how you might use the messaging system composition service. If you have a store named MyStore, and you want to assign two transports, e-mail and file, to the CompanyAOrderCreateMsg message type, you would:
- Add an entry to the VIEWREG table for the JSP file to use for composing this outbound message. The keys for the VIEWREG table are the view name, the store ID, and the device format ID.
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 in the docname field. To summarize:
- INTERFACENAME
- com.ibm.commerce.messaging.viewcommands.MessagingViewCommand
- CLASSNAME
- com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl
- PROPERTIES
- Use the following format to point to the JSP file 'docname=jsp file'.
- DEVICEFMT_ID
- Represents the device format and should use the value -3 (the standard device format) unless using custom device formats for your application. The DEVICEFMT_ID specified in the VIEWREG entry 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 and the message type name with a unique prefix. The following SQL statement would insert a record into the VIEWREG table.
insert into viewreg (VIEWNAME,STOREENT_ID,DEVICEFMT_ID,INTERFACENAME,CLASSNAME,PROPERTIES)values ('CompanyAOrderCreateMsgView',10001,-3, 'ibm.commerce.messaging.viewcommands.MessagingViewCommand' 'ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl', 'docname=CompanyAOrderCreateMsgView.jsp');
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.
- Append &storeDir=no to the JSP file name.
- Place the JSP file in the EAR/Store.war directory.
Note that if there is not a VIEWREG entry for a store, then the VIEWREG entry for the site will be used instead.
- Invoke the compose method of the outbound messaging system interface and pass any additional parameters in the form of a TypedProperty object. By specifying a viewname. You will override the message types default viewname used when composing the message.
- Call sendImediate or sendTransacted on SendMsgCmd if you 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.