Una classe java per inviare messaggi su una coda jms, che vengono scodati
in modalità asincrona.
e così sia..
package it.fastweb.mit.iptv.platform.tvps.test;
import it.fastweb.mit.iptv.platform.tvps.core.msg.TVPSMessageType;
import javax.jms.*;
import javax.naming.*;
import java.util.Hashtable;
public class TVPSJmsTestClient {
// public static final String smqUrl =
// "smqp://localhost:5001/timeout=10000";
public static final String smqUrl = "smqp://10.31.225.28:5001/timeout=10000";
public static final String queueName = "tvps-in-queue@router1";
public static void postMsg(String msgType, String xmlMsg) {
System.out.println("...inPostMsg...");
try {
QueueConnectionFactory queueConnectionFactory = null;
Queue queue = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
QueueSender queueSender = null;
String msgText = xmlMsg;
TextMessage message = null;
System.out.println("Queue name is " + queueName);
Hashtable env = new Hashtable();
Context context = null;
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.swiftmq.jndi.InitialContextFactoryImpl");
env.put(Context.PROVIDER_URL, smqUrl);
context = new InitialContext(env);
queueConnectionFactory = (QueueConnectionFactory) context.lookup("QueueConnectionFactory");
queueConnection = queueConnectionFactory.createQueueConnection();
queueConnection.start();
queueSession = queueConnection.createQueueSession(false,
QueueSession.AUTO_ACKNOWLEDGE);
queue = (Queue) context.lookup(queueName);
System.out.println("found queue " + queueName);
queueSender = queueSession.createSender(queue);
context.close();
queueSender = queueSession.createSender(queue);
message = queueSession.createTextMessage();
message.setText(msgText);
message.setStringProperty("msgType", msgType);
System.out.println("Sending message: " + message.getText());
queueSender.send(message);
} catch (Exception ex) {
System.out.println(".......ECCEZIONE.......");
ex.printStackTrace();
}
}
public static void main(String[] args) {
String[] msgs = new String[10];
String[] msgTypes = { "test", "align-identity", "align-loyalty",
"sky-enable-pay-smc", "sky-disable-all-smc",
"sky-enable-oppv-smc" };
msgs[0] = "\n"
+ "\n"
+ "1234567890\n"
+ "\n"
+ "PIPPO\n"
+ "PLUTO\n" + "\n"
+ "\n";
msgs[1] = "\n"
+ "\n"
+ "1234567890\n"
+ "\n"
+ "bibble22\n" + "\n"
+ "\n";
int num = 3;
postMsg(msgTypes[num], msgs[num]);
}
}