#1 2009-06-03 17:43:48

yansolo82
New member
Registered: 2009-06-03
Posts: 5

iterate on jmsmessage id

Tags: [convert, message, MQ, xml]

hi,

I'm trying to iterate on each xml message I have in my queue (WMQ)

the aim is to make a copy of the xml file
the filename should be the jmsmessageid

I don't know how to do
Thx

Offline

#2 2009-06-04 08:03:06

shong
Talend team
Registered: 2007-08-29
Posts: 10297
Website

Re: iterate on jmsmessage id

Hello
You need to create a routine to convert message to xml file. Here is a scenario,
1) Go to Repository-->Code-->Routines, and right click on Routines, create a new routine called: createXMLFile

Code:

package routines;

import java.io.FileOutputStream;
import java.io.IOException;

public class createXMLFile {

    public static void copyXML(String messageId, String message) {

        byte[] b = new byte[message.length()];
        b = message.getBytes();
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("d:/" + messageId + ".xml");  // d:/ is the dir path.

            fos.write(b);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fos.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    }
}

2) Call the routine on tJavaRow component, as my screenshows.

Best regards

          shong


Uploaded Images


Email:shong@talend.com
Choose Talend, Enjoy Talend!
New & Event: Talend Help Center
Talend-->the leader of open source data management and application integration solutions!

Offline

#3 2009-06-04 10:58:57

yansolo82
New member
Registered: 2009-06-03
Posts: 5

Re: iterate on jmsmessage id

Thanks for your quick reply.

It doesn't work.

The messageid I get is a strange string which is completely different from the big integer I found when I'm browsing the queue with Hermes Jms....

Offline

#4 2009-06-04 11:07:04

shong
Talend team
Registered: 2007-08-29
Posts: 10297
Website

Re: iterate on jmsmessage id

Hello

The messageid I get is a strange string which is completely different from the big integer I found when I'm browsing the queue with Hermes Jms....

Yes, I see the messageid is a strange string by default, so we can cut the messageid with one length, eg:
input_row.messageid.substring(0,2)   
Best regards

          shong


Email:shong@talend.com
Choose Talend, Enjoy Talend!
New & Event: Talend Help Center
Talend-->the leader of open source data management and application integration solutions!

Offline

#5 2009-06-04 11:59:55

yansolo82
New member
Registered: 2009-06-03
Posts: 5

Re: iterate on jmsmessage id

I found the clue

Just have to get the hex value of that strange string to have the full id

Thanks.

Offline

#6 2009-06-04 12:03:15

shong
Talend team
Registered: 2007-08-29
Posts: 10297
Website

Re: iterate on jmsmessage id

Hello

Just have to get the hex value of that strange string

Please take an example to share your clue.smile

Best regards

          shong


Email:shong@talend.com
Choose Talend, Enjoy Talend!
New & Event: Talend Help Center
Talend-->the leader of open source data management and application integration solutions!

Offline

#7 2009-06-04 12:11:45

yansolo82
New member
Registered: 2009-06-03
Posts: 5

Re: iterate on jmsmessage id

Not very clean but it works !!

Code:

package routines;

import java.io.FileOutputStream;
import java.io.IOException;

public class createXMLFile {

    public static void copyXML(String messageId, String message) {

        String mId ="";        
        for (int i=0; i<messageId.length(); i++){
            String temp = Integer.toHexString((int)messageId.charAt(i)).toString();
            if (temp.length()== 1)
                mId+="0"+temp;
            else
                mId+=temp;
        }

        byte[] b = new byte[message.length()];
        b = message.getBytes();
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("d:/" + mId + ".xml");  // d:/ is the dir path.

            fos.write(b);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fos.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    }
}

Last edited by yansolo82 (2009-06-04 12:14:52)

Offline

Board footer

Powered by FluxBB