Dear All,
I written a simplify version of what i am trying to achieve.
Third Party Program Emulator: The program will read some files from an in
folder and generate some files into the out folders. It perform an internal
prioritization based on the properties in the file.
In this simplified example, the output prioritization will be 1.txt, 3.txt,
2.txt in that order, even though the input request is sent as 1.txt, 2.txt
and 3.txt
package my.poc;
import java.io.File;
import java.io.IOException;
import java.nio.channels.FileChannel;
public class FileHelper implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
while(true)
{
File fileOne = new File("C:\\input\\1.txt");
File fileTwo = new File("C:\\input\\2.txt");
File fileThree = new File("C:\\input\\3.txt");
//
if( fileOne.exists() && fileTwo.exists())
{
//Create file 1 in output folder
File outOne = new File("C:\\output\\1.txt");
try {
outOne.createNewFile();
fileOne.delete();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if( fileTwo.exists() && fileThree.exists())
{
//Create file 3 in output folder
File outThree = new File("C:\\output\\3.txt");
fileTwo.delete();
try
{
Thread.sleep(5000);
outThree.createNewFile();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (fileThree.exists())
{
//Create file 2 in output folder
File outTwo = new File("C:\\output\\2.txt");
try {
Thread.sleep(5000);
outTwo.createNewFile();
fileThree.delete();
Thread.sleep(10000);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}
}
}
}
The main program for running the emulator is as follows:
package my.poc;
public class Generator {
public static void main(String[] args)
{
FileHelper helper = new FileHelper();
Thread thread = new Thread(helper);
thread.start();
}
}
____________________________________________________________________________________The
code for running my service Apps. the standalone camelcontext that is
listening to request and generating the input requested by the third party
software:
package my.poc.server;
import org.apache.camel.spring.Main;
/**
* A main class to run the example from your editor.
*/
public class ServerMain {
private ServerMain()
{
}
public static void main(String[] args) throws Exception {
// Main makes it easier to run a Spring application
Main main = new Main();
// configure the location of the Spring XML file
main.setApplicationContextUri("META-INF/spring/camel-context.xml");
// enable hangup support allows Camel to detect when the JVM is
terminated
main.enableHangupSupport();
// run and block until Camel is stopped (or JVM terminated)
main.run();
}
}
The camel-context:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://bhtan:61616"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:topic:request"/>
<to uri="log:foo"/>
<to uri="file:c://input?fileName=${body}.txt"/>
</route>
<route>
<from uri="file:c://output"/>
<to uri="log:foo"/>
</route>
</camelContext>
</beans>
____________________________________________________________________________________The
client code is the same as the standalone, here is the camel context
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://bhtan:61616"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="stream:in?promptMessage=Enter Requested Record: "/>
<transform>
<simple>${body.toUpperCase()}</simple>
</transform>
<inOut uri="activemq:topic:request"/>
<to uri="stream:out"/>
</route>
</camelContext>
</beans>
____________________________________________________________________________________
Here are the output for runnung the 3 systems
Client Result;
Enter Requested Record: 1
1
Enter Requested Record: 2
2
Enter Requested Record: 3
3
Server Result:
[read #0 - JmsConsumer[request]] foo INFO
Exchange[ExchangePattern:InOut, BodyType:String, Body:1]
[read #0 - JmsConsumer[request]] foo INFO
Exchange[ExchangePattern:InOut, BodyType:String, Body:2]
[ thread #1 - file://c://output] foo INFO
Exchange[ExchangePattern:InOnly,
BodyType:org.apache.camel.component.file.GenericFile, Body:[Body is file
based: GenericFile[c:\output\1.txt]]]
[read #0 - JmsConsumer[request]] foo INFO
Exchange[ExchangePattern:InOut, BodyType:String, Body:3]
[ thread #1 - file://c://output] foo INFO
Exchange[ExchangePattern:InOnly,
BodyType:org.apache.camel.component.file.GenericFile, Body:[Body is file
based: GenericFile[c:\output\3.txt]]]
[ thread #1 - file://c://output] foo INFO
Exchange[ExchangePattern:InOnly,
BodyType:org.apache.camel.component.file.GenericFile, Body:[Body is file
based: GenericFile[c:\output\2.txt]]]
__________________________________________________________________________
I believe that based on the server output, it did not attempt a dynamic
temp-queue respond back to the client,
my main question is how do i make sure that the respond;
[ thread #1 - file://c://output] foo INFO
Exchange[ExchangePattern:InOnly,
BodyType:org.apache.camel.component.file.GenericFile, Body:[Body is file
based: GenericFile[c:\output\3.txt]]]
Is sent to the correct client instead of the 2nd client.
Although in this cases, I'm only running a single instance of the client,
but in actual scenario, there will be multile instances of the client
running.
The most worrying issue is, my code isnt waiting for an respond. what did i
do wrongly?
Thanks and Best Regards,
Zuff
--
View this message in context:
http://camel.465427.n5.nabble.com/Best-Practise-for-Dynamic-Topic-in-Ear-Project-tp5720288p5721017.html
Sent from the Camel - Users mailing list archive at Nabble.com.