TextMassige routing hjælp ?

Tags:    java

jeg prøver at lave en simpel Router med 3 ud queue's
men det går galt.

hvis der er nogen der kan sende et lille kode eksempel vil jeg blive glad.

her er den klasse der levere den oprindelige besked.



import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;

import java.io.IOException;
import java.io.InputStreamReader;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import javax.naming.NamingException;

import org.w3c.dom.Document;

//~--- classes ------------------------------------------------------------------------------------

public class Requestor {
private MessageProducer invalidProducer;
private MessageConsumer replyConsumer;
private Destination replyQueue;
private MessageProducer requestProducer;
private Session session;

//~--- constructors ---------------------------------------------------------------------------

protected Requestor() {
super();
}

//~--- methods --------------------------------------------------------------------------------

protected void initialize(Connection connection, String requestQueueName,
String replyQueueName, String invalidQueueName)
throws JMSException, NamingException {
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

Destination requestQueue = JndiUtil.getDestination(requestQueueName);

replyQueue = JndiUtil.getDestination(replyQueueName);

Destination invalidQueue = JndiUtil.getDestination(invalidQueueName);

requestProducer = session.createProducer(requestQueue);
replyConsumer = session.createConsumer(replyQueue);
invalidProducer = session.createProducer(invalidQueue);
}

public static Requestor newRequestor(Connection connection, String requestQueueName,
String replyQueueName, String invalidQueueName)
throws JMSException, NamingException {
Requestor requestor = new Requestor();

requestor.initialize(connection, requestQueueName, replyQueueName, invalidQueueName);

return requestor;
}

public void recieveSync() throws JMSException {
Message msg = replyConsumer.receive();

if (msg instanceof TextMessage) {
TextMessage replyMessage = (TextMessage) msg;

System.out.println("Recieved reply");
System.out.println("\\tTime: " + System.currentTimeMillis() + " ms");
System.out.println("\\tMessage ID: " + replyMessage.getJMSMessageID());
System.out.println("\\tCorrel. ID: " + replyMessage.getJMSCorrelationID());
System.out.println("\\tReply to: " + replyMessage.getJMSReplyTo());
System.out.println("\\tContents: " + replyMessage.getText());
} else {
System.out.println("Invalid message detected");
System.out.println("\\tType: " + msg.getClass().getName());
System.out.println("\\tTime: " + System.currentTimeMillis() + " ms");
System.out.println("\\tMessage ID: " + msg.getJMSMessageID());
System.out.println("\\tCorrel. ID: " + msg.getJMSCorrelationID());
System.out.println("\\tReply to: " + msg.getJMSReplyTo());
msg.setJMSCorrelationID(msg.getJMSMessageID());
invalidProducer.send(msg);
System.out.println("Sent to invalid message queue");
System.out.println("\\tType: " + msg.getClass().getName());
System.out.println("\\tTime: " + System.currentTimeMillis() + " ms");
System.out.println("\\tMessage ID: " + msg.getJMSMessageID());
System.out.println("\\tCorrel. ID: " + msg.getJMSCorrelationID());
System.out.println("\\tReply to: " + msg.getJMSReplyTo());
}
}

public void send() throws JMSException {
TextMessage requestMessage = session.createTextMessage();

requestMessage.setText("Hello world.");
requestMessage.setJMSReplyTo(replyQueue);
requestProducer.send(requestMessage);
System.out.println("Sent request");
System.out.println("\\tTime: " + System.currentTimeMillis() + " ms");
System.out.println("\\tMessage ID: " + requestMessage.getJMSMessageID());
System.out.println("\\tCorrel. ID: " + requestMessage.getJMSCorrelationID());
System.out.println("\\tReply to: " + requestMessage.getJMSReplyTo());
System.out.println("\\tContents: " + requestMessage.getText());
}
public void sendDoc()throws JMSException,
FileNotFoundException,
IOException {
// InputStreamReader str = new InputStreamReader()

String ib="" ;
FileReader fr = new FileReader("doc1fil.txt");
BufferedReader inFile = new BufferedReader(fr);

System.out.println("Filens indhold:");
String line = inFile.readLine();
while (line != null)
{
System.out.println(line);
line = inFile.readLine();
ib+= line;
}

TextMessage requestMessage = session.createTextMessage();
requestMessage.setText(ib);


}

}




At skrive "Det går galt" hjælper ca. lige så meget som hvis jeg svarer "Der er en fejl". Fortæl hvar der går galt og hvordan og hvornår og med hvilke parametre etc. Så er det lidt nemmere at hjælpe.



t