|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Can not connect using Sender Channel |
« View previous topic :: View next topic » |
Author |
Message
|
Manzoor Nawaz |
Posted: Fri Sep 01, 2006 3:52 am Post subject: Can not connect using Sender Channel |
|
|
Newbie
Joined: 01 Sep 2006 Posts: 2
|
I have faced a exception,when I use Sender Channel for connection MQRC_CONNECTION_BROKEN exception occurs.
but
when I use Server Channel it goes correctly..
So,how can I handle this..
this is my application code given below:
/*
* TestBean.java
*
* Created on August 30, 2006, 4:27 PM
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
package beans;
import com.ibm.mq.MQMessage;
import java.util.ArrayList;
import java.util.Iterator;
/**
*
* @author Administrator
*/
public class TestBean
{
/** Creates a new instance of TestBean */
public TestBean()
{
}
public static void main(String args[])
{
MQBean.setMQEnvironment("192.168.2.26", "MQ1ECN.TO.MQ1P", 1414);
MQBean.openConnection("MQ1ECN", "MQ1ECN.DDSFAX.ADV.LOCALQ", 1);
MQBean.setMQMessage("TEST MESSAGE from Tariq");
MQBean.closeConnection();
/* MQBean.openConnection("MyQueueManager", "LocalQueue", 0);
ArrayList al = MQBean.getMQMessages();
Iterator ite = al.iterator();
while(ite.hasNext())
{
MQMessage msg = (MQMessage) ite.next();
try
{
System.out.println(msg);
}
catch(Exception e)
{
e.getMessage();
e.printStackTrace();
}
}
System.out.println(MQBean.getMQMessageAsString());
MQBean.closeConnection();*/
System.exit(0);
}
}
/*
* MQBean.java
*
* Created on August 29, 2006, 12:29 PM
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
package beans;
import com.ibm.mq.*;
import java.util.ArrayList;
/**
*
* @author Tariq Siddiqui
*/
public class MQBean
{
private static MQMessage mqMessage;
private static MQQueue queue;
private static MQQueueManager queueManager;
/** Creates a new instance of MQBean */
public MQBean()
{
}
/**
* Sets the environment for MQ Connection
*/
public static void setMQEnvironment(String hostName, String channel, int port)
{
MQEnvironment.properties.put(MQC.HOST_NAME_PROPERTY, hostName);
MQEnvironment.properties.put(MQC.CHANNEL_PROPERTY, channel);
MQEnvironment.properties.put(MQC.PORT_PROPERTY, port);
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES);
}
/**
*
*/
public static void openConnection(String qmName, String qName, int openFor)
{
try
{
queueManager = new MQQueueManager(qmName);
int openOptions = -1 ;
switch(openFor)
{
case 0:
openOptions = MQC.MQOO_INPUT_SHARED | MQC.MQOO_FAIL_IF_QUIESCING;
break;
case 1:
openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;
break;
case 2:
openOptions = MQC.MQOO_BROWSE | MQC.MQOO_FAIL_IF_QUIESCING;
break;
}
queue = queueManager.accessQueue(qName, openOptions);
}
catch(MQException mqe)
{
System.err.println("MQ Error: Completion Code : " + mqe.completionCode + " Reason Code : " + mqe.reasonCode);
}
}
/**
*
*/
public static void closeConnection()
{
try
{
queue.close();
queueManager.disconnect();
}
catch(MQException mqe)
{
System.err.println("MQ Error: Completion Code : " + mqe.completionCode + " Reason Code : " + mqe.reasonCode);
}
}
/**
* Use to put message in a queue.
*/
public static void setMQMessage(String msg)
{
try
{
MQPutMessageOptions pmo = new MQPutMessageOptions();
mqMessage = new MQMessage();
mqMessage.format = MQC.MQFMT_STRING;
mqMessage.replyToQueueManagerName = "MQ1ECN";
mqMessage.replyToQueueName = "MQ1ECN.DDSFAX.ADV.LOCALQ";
mqMessage.writeString(msg);
queue.put(mqMessage , pmo);
}
catch (MQException ex)
{
System.err.println("An MQ error occured: Completion code " + ex.completionCode + " Reason code " + ex.reasonCode);
}
catch (java.io.IOException e)
{
System.err.println("An error occured writing to the message buffer " + e);
}
}
/**
* Use to get message from a queue.
*/
public static String getMQMessageAsString()
{
try
{
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_FAIL_IF_QUIESCING;
mqMessage = new MQMessage();
queue.get(mqMessage, gmo);
String msg = mqMessage.readString(mqMessage.getMessageLength());
return msg;
}
catch (MQException ex)
{
System.out.println("An MQ error occured: Completion code " + ex.completionCode + " Reason code " + ex.reasonCode);
return null;
}
catch (java.io.IOException e)
{
System.out.println("An error occured writing to the message buffer " + e);
return null;
}
}
/**
*
*/
public static MQMessage getMQMessageAsObject()
{
try
{
MQGetMessageOptions gmo=new MQGetMessageOptions();
gmo.options = MQC.MQGMO_FAIL_IF_QUIESCING;
mqMessage = new MQMessage();
queue.get(mqMessage, gmo);
return mqMessage;
}
catch (MQException ex)
{
System.out.println("An MQ error occured: Completion code " + ex.completionCode + " Reason code " + ex.reasonCode);
return null;
}
}
/**
*
*/
public static ArrayList getMQMessages()
{
ArrayList alMsg = new ArrayList();
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST;
mqMessage = new MQMessage();
for(int i=1; i<=50; i++)
{
try
{
mqMessage.clearMessage();
mqMessage.correlationId = MQC.MQCI_NONE;
mqMessage.messageId = MQC.MQMI_NONE;
queue.get(mqMessage , gmo);
//String msg = mqMessage.readString(mqMessage.getMessageLength());
alMsg.add(mqMessage);
gmo.options = MQC.MQGMO_BROWSE_NEXT;
}
catch (MQException ex)
{
System.out.println("MQ exception: CC = " + ex.completionCode + " RC = " + ex.reasonCode);
break;
}
catch (java.io.IOException ex)
{
System.out.println("Java exception: " + ex);
break;
}
}
return alMsg;
}
} |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Sep 01, 2006 3:59 am Post subject: Re: Can not connect using Sender Channel |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
That's correct.
You can NOT use a Sender channel for an application connection.
You must use a Server Connection Channel and a Client Connection Channel.
The Client Connection channel part is usually implicit.
Welcome to MQ. Please read the documentation. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Vitor |
Posted: Fri Sep 01, 2006 4:00 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Functioning as designed - sender channels pair with receiver channels.
RTFM  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|