Jump to content
OpenSplice DDS Forum
Sign in to follow this  
getviswa

Message Instance and Samples

Recommended Posts

Hello All,

 

I am trying to publish the sequence of messages in the topic. I can publish it successfully but i trying to subscribe the messages i am getting last message which i was published.

 

Note I have used HelloWorld: DDSEntityManager.java from the example.

 

Publisher Code:

public static void messagePublisher(String devMessage,String devMessageType, String devDeviceSerialType,String devAction )
{
	SimpleDDS mgr = new SimpleDDS();
	String partitionName = "MessageService";
  	 mgr.createParticipant(partitionName);
  	 DDSMessageTypeSupport msgTS = new DDSMessageTypeSupport();
	mgr.registerType(msgTS);
  	 mgr.createTopic("Messages");
  	 mgr.createPublisher();
  	 mgr.createWriter();
  	 DataWriter dwriter = mgr.getWriter();
	DDSMessageDataWriter ddsWriter = DDSMessageDataWriterHelper.narrow(dwriter);
	DDSMessage msgInstance = new DDSMessage(devDeviceSerialType, devMessageType, devAction, devMessage);
  	 ddsWriter.register_instance(msgInstance);
	int status = ddsWriter.write(msgInstance, HANDLE_NIL.value);
	ErrorHandler.checkStatus(status, "DDSMessageDataWriter.write");
  	 try {
   	   Thread.sleep(1000);
  	 } catch (InterruptedException e) {
	e.printStackTrace();
  	 }
   mgr.getPublisher().delete_datawriter(ddsWriter);
   mgr.deletePublisher();
   mgr.deleteTopic();
   mgr.deleteParticipant();
   try {
	Thread.sleep(200);
   } catch (InterruptedException e) {
   e.printStackTrace();
  }
}

public static void main(String[] args) {

messagePublisher("112-2134354","response","XMLMessage","123");
messagePublisher("112-2134354","response","XMLMessage","1234");
messagePublisher("230-4353456","response","XMLMessage","12345");
}

 

 

Subscriber Code:

public static void messageSubscriber(String args) {
	SimpleDDS mgr = new SimpleDDS();
	String partitionName = "MessageService";
  	 mgr.createParticipant(partitionName);
  	 DDSMessageTypeSupport msgTS = new DDSMessageTypeSupport();
	mgr.registerType(msgTS);
  	 mgr.createTopic("Messages");
  	 mgr.createSubscriber();
  	 mgr.createReader();
  	 DataReader dreader = mgr.getReader();
	DDSMessageDataReader ddsReader = DDSMessageDataReaderHelper.narrow(dreader);
  	 DDSMessageSeqHolder msgSeq = new DDSMessageSeqHolder();
	SampleInfoSeqHolder infoSeq = new SampleInfoSeqHolder();
	boolean terminate = false;
	int count = 0;
	while (!terminate && count < 1500) {
		ddsReader.take(msgSeq, infoSeq, LENGTH_UNLIMITED.value,
		ANY_SAMPLE_STATE.value, ANY_VIEW_STATE.value,
		ANY_INSTANCE_STATE.value);
		System.out.println(msgSeq.value.length);

		for (int i = 0; i < msgSeq.value.length; i++) {

				System.out.println("	userID  : "
						+ msgSeq.value[i].deviceSerialType);
				System.out.println("	type : "
						+ msgSeq.value[i].messageType);
				System.out.println("	action : "
						+ msgSeq.value[i].actionType);
				System.out.print("	Message : \""
						+ msgSeq.value[i].message + "\"");
				//terminate = true;

		}
		try
		{
			Thread.sleep(200);
		}
		catch(InterruptedException ie)
		{
			// nothing to do
		}
		++count;

	}


			ddsReader.return_loan(msgSeq, infoSeq);

	mgr.getSubscriber().delete_datareader(ddsReader);
	mgr.deleteSubscriber();
	mgr.deleteTopic();
	mgr.deleteParticipant();

}
public static void main(String[] args) {
	messageSubscriber("test");
}

 

 

But Subscriber resulting last message which is published. Please help me.

userID : XMLMessage

type : response

action : 12345

Message : "230-4353456"

 

 

Thanks

-Viswa

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×