I am using the j-interop to work on MSMQ.
By using the MSMQ i can send the messages to MSMQ but i am not able receive the messages. I got an exception.
public class MyQueue {
/*
{D7D6E082-DCCD-11D0-AA4B-0060970DEBAE} MSMQCoordinatedTransactionDispenser Object MSMQ.MSMQCoordinatedTransactionDispenser.1
{D7D6E084-DCCD-11D0-AA4B-0060970DEBAE} MSMQTransactionDispenser Object MSMQ.MSMQTransactionDispenser.1
{D7D6E086-DCCD-11D0-AA4B-0060970DEBAE} MSMQApplication Object MSMQ.MSMQApplication.1 */
private static final String MSMQ_MSMQQuery_1 = "D7D6E073-DCCD-11D0-AA4B-0060970DEBAE";
private static final String MSMQ_MSMQMessage_1 = "D7D6E075-DCCD-11D0-AA4B-0060970DEBAE";
private static final String MSMQ_MSMQQueue_1 = "D7D6E079-DCCD-11D0-AA4B-0060970DEBAE";
private static final String MSMQ_MSMQEvent_1 = "D7D6E07A-DCCD-11D0-AA4B-0060970DEBAE";
private static final String IMSMQPrivateEvent = "D7AB3341-C9D3-11D1-BB47-0080C7C5A2C0";
private static final String MSMQ_MSMQQueueInfo_1 = "D7D6E07C-DCCD-11D0-AA4B-0060970DEBAE";
private static final String MSMQ_MSMQQueueInfos_1 = "D7D6E07E-DCCD-11D0-AA4B-0060970DEBAE";
private static final String MSMQ_MSMQTransaction_1 = "D7D6E080-DCCD-11D0-AA4B-0060970DEBAE";
queueInfoDispatcher.addRef();
// Set queue name !
queueInfoDispatcher.put("FormatName", new JIVariant(new JIString(
FormatName)));
// Create the queue
JIVariant results = queueInfoDispatcher.callMethodA("Open",
new Object { new Integer(2), new Integer(0) });
// Set Body and Subject
messageDispatcher.put("body", new JIVariant(new JIString(body)));
messageDispatcher.put("label", new JIVariant(new JIString(label)));
messageDispatcher.put("Priority", new Object{ new Integer(7)});
// Post the message
messageDispatcher.callMethodA("send",new Object { queueDispatcher });
}
}
public void getAllMessage()throws JIException {
?????
}
void clean() throws JIException {
// Close the queue
queueDispatcher.callMethod("Close");
// Close session
JISession.destroySession(queueInfoDispatcher.getAssociatedSession());
JISession.destroySession(messageDispatcher.getAssociatedSession());
}
public static void main(String args) throws JIException {
if (args.length < 4) {
System.out.println("Please provide address domain username password");
return;
}
String s = "Hi This is my Test Message from UNIX";
//for(int j=0; j<3000 ;j++){
//s += "abcdefghijklm";
//}
MyQueue Q = new MyQueue(args, args, args, args);
try {
int i=0;
System.out.println(i);
System.out.println("I am sending the message");
Q.sendMessage(GregorianCalendar.getInstance().getTime().toString() +" -Id: " + i++, s);
//Q.getAllMessage();
}
Hi All,
I am using the j-interop to work on MSMQ.
By using the MSMQ i can send the messages to MSMQ but i am not able receive the messages. I got an exception.
public class MyQueue {
/*
{D7D6E082-DCCD-11D0-AA4B-0060970DEBAE} MSMQCoordinatedTransactionDispenser Object MSMQ.MSMQCoordinatedTransactionDispenser.1
{D7D6E084-DCCD-11D0-AA4B-0060970DEBAE} MSMQTransactionDispenser Object MSMQ.MSMQTransactionDispenser.1
{D7D6E086-DCCD-11D0-AA4B-0060970DEBAE} MSMQApplication Object MSMQ.MSMQApplication.1 */
private static final String MSMQ_MSMQQuery_1 = "D7D6E073-DCCD-11D0-AA4B-0060970DEBAE";
private static final String MSMQ_MSMQMessage_1 = "D7D6E075-DCCD-11D0-AA4B-0060970DEBAE";
private static final String MSMQ_MSMQQueue_1 = "D7D6E079-DCCD-11D0-AA4B-0060970DEBAE";
private static final String MSMQ_MSMQEvent_1 = "D7D6E07A-DCCD-11D0-AA4B-0060970DEBAE";
private static final String IMSMQPrivateEvent = "D7AB3341-C9D3-11D1-BB47-0080C7C5A2C0";
private static final String MSMQ_MSMQQueueInfo_1 = "D7D6E07C-DCCD-11D0-AA4B-0060970DEBAE";
private static final String MSMQ_MSMQQueueInfos_1 = "D7D6E07E-DCCD-11D0-AA4B-0060970DEBAE";
private static final String MSMQ_MSMQTransaction_1 = "D7D6E080-DCCD-11D0-AA4B-0060970DEBAE";
private String domain;
private String user;
private String password;
private String host;
private String FormatName = "direct=os:.\\private$\\aa";
private JIComServer queueInfoStub = null;
private IJIComObject queueInfoInstance = null;
private IJIDispatch queueInfoDispatcher = null;
private IJIDispatch queueDispatcherForReceiveMode = null;
private IJIDispatch queueDispatcher = null;
private IJIDispatch messageDispatcher = null;
//private JIComFactory ComFactory = null;
public MyQueue(String domain, String user, String password, String host) {
this.domain = domain;
this.user = user;
this.password = password;
this.host = host;
// create the queue info
try {
JISession sessionInfo = JISession.createSession(domain, user, password);
queueInfoStub = new JIComServer(JIProgId.valueOf("MSMQ.MSMQQueueInfo"),host, sessionInfo);
queueInfoInstance = queueInfoStub.createInstance();
queueInfoDispatcher = (IJIDispatch)JIObjectFactory.narrowObject(queueInfoInstance.queryInterface(IJIDispatch.IID));
//queueInfoDispatcher = (IJIDispatch) ComFactory.createCOMInstance(
//ComFactory.IID_IDispatch, queueInfoInstance);
queueInfoDispatcher.addRef();
// Set queue name !
queueInfoDispatcher.put("FormatName", new JIVariant(new JIString(
FormatName)));
// Create the queue
JIVariant results = queueInfoDispatcher.callMethodA("Open",
new Object { new Integer(2), new Integer(0) });
//JIInterfacePointer ptr = results.getObjectAsInterfacePointer();
//queueDispatcher = (IJIDispatch)JIObjectFactory.narrowObject(queueInfoInstance, ptr);
queueDispatcher = (IJIDispatch)JIObjectFactory.narrowObject(results.getObjectAsComObject());
//queueDispatcher = (IJIDispatch) ComFactory.createCOMInstance(
//queueInfoInstance, ptr);
JISession sessionMessage = JISession.createSession(domain, user, password);
JIComServer messageStub = new JIComServer(JIClsid.valueOf(MSMQ_MSMQMessage_1), host, sessionMessage);
// create the queue message
IJIComObject msgInstance = messageStub.createInstance();
messageDispatcher = (IJIDispatch)JIObjectFactory.narrowObject(msgInstance.queryInterface(IJIDispatch.IID));
//messageDispatcher = (IJIDispatch) ComFactory.createCOMInstance(ComFactory.IID_IDispatch, msgInstance);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (JIException e) {
e.printStackTrace();
}
}
public void sendMessage(String label, String body) throws JIException {
{
queueDispatcher.addRef();
messageDispatcher.addRef();
// Set Body and Subject
messageDispatcher.put("body", new JIVariant(new JIString(body)));
messageDispatcher.put("label", new JIVariant(new JIString(label)));
messageDispatcher.put("Priority", new Object{ new Integer(7)});
// Post the message
messageDispatcher.callMethodA("send",new Object { queueDispatcher });
}
}
public void getAllMessage()throws JIException {
?????
}
void clean() throws JIException {
// Close the queue
queueDispatcher.callMethod("Close");
// release resources
queueDispatcher.release();
queueInfoDispatcher.release();
messageDispatcher.release();
// Close session
JISession.destroySession(queueInfoDispatcher.getAssociatedSession());
JISession.destroySession(messageDispatcher.getAssociatedSession());
}
public static void main(String args) throws JIException {
if (args.length < 4) {
System.out.println("Please provide address domain username password");
return;
}
String s = "Hi This is my Test Message from UNIX";
//for(int j=0; j<3000 ;j++){
//s += "abcdefghijklm";
//}
MyQueue Q = new MyQueue(args, args, args, args);
try {
int i=0;
System.out.println(i);
System.out.println("I am sending the message");
Q.sendMessage(GregorianCalendar.getInstance().getTime().toString() +" -Id: " + i++, s);
//Q.getAllMessage();
}
catch (JIException e) {
e.printStackTrace();
}
Q.clean();
}
}
Can anybody please help? Thanks in Advance.
what exception did you get? please paste the stack trace, too.
Hi again,
Thanks for your reply.
public void getAllMessage()throws JIException {
try{
JIVariant results = queueInfoDispatcher.callMethodA("Open",new Object { new Integer(1), new Integer(0) });
queueDispatcherForReceiveMode = (IJIDispatch)JIObjectFactory.narrowObject(results.getObjectAsComObject());
queueDispatcherForReceiveMode.addRef();
JIVariant var = queueDispatcherForReceiveMode.callMethodA("receive",new Object { new Integer(2), new Integer(0) });
IJIDispatch dispatch = (IJIDispatch) JIObjectFactory.narrowObject(var.getObjectAsComObject());
System.out.println("*******************************************************************");
System.out.println("LABEL***: " + dispatch.get("label").getObjectAsString2());
System.out.println("BODY****: " + (dispatch.get("body")).getObjectAsString2());
System.out.println("*******************************************************************");
}catch(Exception e){
e.printStackTrace();
}
}
this will get the message..