Author |
Message
|
phaniIIB |
Posted: Tue Apr 12, 2016 11:24 am Post subject: Unable to create MbMessage Object in Java Runnable Class |
|
|
Acolyte
Joined: 28 Jul 2015 Posts: 51
|
Hi all,
I am trying to develop a multi-threading scenario where I have a JCN as Main Class and a Runnable Class.
In the Runnable Class I have the following code,
Code: |
MbMessage outMessage=new MbMessage();
outMessage.getRootElement().createElementAsLastChild(MbBLOB.PARSER_NAME).createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", data.getBytes());
MbElement outRoot = outMessage.getRootElement();
// Create the Broker Blob Parser element
MbElement outParser = outRoot.createElementAsLastChild(MbBLOB.PARSER_NAME);
// Create the BLOB element in the Blob parser domain with the required text
MbElement outBody = outParser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", data.getBytes());
byte[] messageBodyByteArray = (byte[]) (outMessage.getRootElement().getFirstElementByPath("/BLOB/BLOB").getValue());
String messageBodyString = new String(messageBodyByteArray);
System.out.println("The message propagated is "+messageBodyString);
MbMessageAssembly outAssembly = new MbMessageAssembly(contact admin, outMessage);
out.propagate(outAssembly); |
But while creating the outMessage(MbMessage outMessage=new MbMessage()) the thread exits out of the task with out any Exception being logged.
Did anyone face this issue. Please suggest.
Thanks in advance |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Apr 12, 2016 1:54 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Please explain what you know ab out JCN and threading... _________________ MQ & Broker admin |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Apr 13, 2016 4:07 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
In general, implementing your own threading in a transformation node (JCN, NetCN, PHPCn... ) is a bad idea. You can easily cause the EG to crash or overload memory or lock up waiting on thread completion.
If you are seeing failures in Java code, the usual thing is to wrap them in try/catch blocks.
If you see a broker flow exit when it doesn't need to, then either an error has occurred that will be logged *somewhere*, or your flow logic doesn't do what you think it does.
With any kind of propagate, you need to make sure you know when to return true and when to return false.
User trace can be very helpful. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
phaniIIB |
Posted: Wed Apr 13, 2016 5:53 am Post subject: |
|
|
Acolyte
Joined: 28 Jul 2015 Posts: 51
|
Thanks,
In this case are we telling that IIB or Message broker cannot handle parallel processing of tasks or Is there any other way to implement this. Please suggest. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Apr 13, 2016 6:22 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
phaniIIB wrote: |
Thanks,
In this case are we telling that IIB or Message broker cannot handle parallel processing of tasks or Is there any other way to implement this. Please suggest. |
I'm saying don't write your own threads.
That's entirely different than saying you can't do parallel processing.
What is a message flow? How does it run? Can you run more copies of a message flow at once? How does that work? What kind of thing runs a message flow?
Let me put it another way.
Forget everything you know about writing java service apps or servers.
Follow the samples for Message Broker about using JCNs. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
phaniIIB |
Posted: Wed Apr 13, 2016 9:59 am Post subject: |
|
|
Acolyte
Joined: 28 Jul 2015 Posts: 51
|
I think the discussion is going in a wrong track. The question here is, What is happening when I create an MbMessage during a thread task. Why should I not create Threads in Java compute node. If not how will I be able to perform this usecase in IIB. Can someone please suggest. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Apr 13, 2016 10:31 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
phaniIIB wrote: |
I think the discussion is going in a wrong track. |
No it isn't.
phaniIIB wrote: |
The question here is, What is happening when I create an MbMessage during a thread task. |
What's happening is you're trying to use a thread task.
phaniIIB wrote: |
Why should I not create Threads in Java compute node. |
Because, as my associates have pointed out, threading should be left to the control of the software.
phaniIIB wrote: |
If not how will I be able to perform this usecase in IIB. |
Using the software threading model. Again, as my associates have said. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Apr 13, 2016 11:04 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
phaniIIB wrote: |
Why should I not create Threads in Java compute node. |
Because that's not the threading model in IIB.
phaniIIB wrote: |
If not how will I be able to perform this usecase in IIB. Can someone please suggest. |
By using the threading model in IIB. That model can be understood by answering these questions :
mqjeff wrote: |
What is a message flow? How does it run? Can you run more than one copy of a message flow at once? How does that work? What kind of thing runs a message flow? |
You are trying to do things that are normal in a standalone Java app or in a java app server.
IIB is neither. A JCN runs inside neither.
Review the IIB JCN samples. Review the documentation that discusses the execution model of IIB. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
|