Skip to main content
Skip table of contents

Publishing XML Messages

For the Publisher sample to use CBR, set the value of InitialContext environment variable UseFioranoCbr to true. To use CBR related proprietary APIs, the package fiorano.jms.runtime.xpubsub needs to be imported. XML messages are sent as contents of FioranoXMLMessages.

FioranoXMLMessages in JMS terminology are text messages and can be created using FioranoTopicSession.

Below is a code snippet for creating a publisher with which to publish XML messages.

CODE
/**
* @(#)FCRPublisher.java 1.0, 04/25/2001
*
* Publishes 3 xml messages on the topic specified by client.
* The mode of delivery can be both persistent and non-persistent.
* One of these messages would be received by the XCRSubscriber sample.
*
* Copyright (c) 2001 by Fiorano Software, Inc.,
* Los Gatos, California, 95030, U.S.A.
* All rights reserved.
*
* This software is the confidential and proprietary information
* of Fiorano Software, Inc. ("Confidential Information"). You
* shall not disclose such Confidential Information and shall use
* it only in accordance with the terms of the license agreement
* enclosed with this product or entered into with Fiorano.
*/ [Style check please]
import javax.jms.*;
import java.util.*;
import javax.naming.*;
import fiorano.jms.services.msg.def.*;
import fiorano.jms.runtime.xpubsub.*;
import fiorano.jms.runtime.naming.FioranoJNDIContext;
public class FCRPublisher
{
public static void main( String args[] ) throws Exception
{
Hashtable env = new Hashtable();
env.put (Context.SECURITY_PRINCIPAL, "anonymous");
env.put (Context.SECURITY_CREDENTIALS, "anonymous");
env.put (Context.PROVIDER_URL,
"http://localhost:1856" );
env.put (Context.INITIAL_CONTEXT_FACTORY,
"fiorano.jms.runtime.naming.FioranoInitialContextFactory");
InitialContext ic = new InitialContext (env);
TopicConnectionFactory tcf =
(TopicConnectionFactory) ic.lookup ("primaryTCF");
TopicConnection topicConnection = tcf.createTopicConnection();
Topic topic = (Topic)ic.lookup("primaryTopic");
FioranoTopicSession topicSession =
(FioranoTopicSession)topicConnection.createTopicSession(false,1);
TopicPublisher topicPublisher = topicSession.createPublisher(topic);
System.out.println("Starting message delivery ....");
FioranoXMLMessage tMsg1 = topicSession.createXMLMessage();
FioranoXMLMessage tMsg2 = topicSession.createXMLMessage();
FioranoXMLMessage tMsg3 = topicSession.createXMLMessage();
String[] sym = {"MSFT","IBM","HWP"};
int[] price = {40,50,60};
String[] xml = new String[3];
for(int i=0;i<3;i++)
{
xml[i] = "<quote>";
xml[i] = xml[i] + "<symbol>"+ sym[i] +"</symbol>";
xml[i] = xml[i] + "<askprice>"+ price[i] +"</askprice>";
xml[i] = xml[i] + "</quote>";
}
try
{
// setting the xml to the text messages
tMsg1.setText(xml[0]);
tMsg2.setText(xml[1]);
tMsg3.setText(xml[2]);
tMsg1.setJMSDeliveryMode (DeliveryMode.NON_PERSISTENT);
tMsg2.setJMSDeliveryMode (DeliveryMode.NON_PERSISTENT);
tMsg3.setJMSDeliveryMode (DeliveryMode.NON_PERSISTENT);
topicPublisher.publish(tMsg1);
System.out.println("Published the message :: " + xml[0]);
topicPublisher.publish(tMsg2);
System.out.println("Published the message :: " + xml[1]);
topicPublisher.publish(tMsg3);
System.out.println("Published the message :: " + xml[2]);
}
catch( Exception e )
{
System.out.println("Exception in publishing:" +e );
}
}
}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.