Example of using the messaging system composition service

The following is an example of how you might use the messaging system composition service. If you have a store named DemoStore and you want to assign two transports, e-mail and file, to the OrderAuthorized message type, you would do the following:

  1. 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. For more information on how the VIEWREG table is used, refer to the WebSphere Commerce Programming Guide and Tutorials.

    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.

    For example, if the store ID for DemoStore were 5 and the viewname is OrderAuthorized you could insert a record using the following SQL statement:

    insert into viewreg (VIEWNAME,STOREENT_ID,DEVICEFMT_ID,INTERFACENAME,CLASSNAME,
        PROPERTIES)values
    
        ('OrderAuthorizedView',5,-3,
    
        'com.ibm.commerce.messaging.viewcommands.MessagingViewCommand'
    
        'com.ibm.commerce.messaging.viewcommands.MessagingViewCommandImpl',
    
        'docname=OrderAuthorized.jsp');
    
  2. Use the Administration Console to assign the e-mail and file transports to the OrderAuthorized 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.
  3. In the implementation of a command, instantiate the SendMsgCmd command to use messaging services and call the setMsgType() and setStoreID() methods, using the message ID of the OrderAuthorized message type and the store ID of DemoStore. If you need to use site-level configuration, specify 0 as the store ID and attach "&storeDir=no" at the end of the JSP name. Otherwise, use your store ID. (If no configuration exists for your store, the Messaging System defaults to site-level configuration automatically.)
  4. 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.
  5. 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.
  6. Call execute method of the SendMsgCmd to execute sending.