내 코드 :
//Initialize MQMessage
MQMessage message = new MQMessage();
//Initialize WebMQConnection
WebSphereMQConnection mqRequestConnection = new WebSphereMQConnection(initQMName, initQChannel, initQConnection, initQName, string.Empty, string.Empty);
mqRequestConnection.Open();
mqRequestConnection.Read(message);
//Get the contents as a string
string body = message.ReadString(message.MessageLength);
return body;
이 코드는 콘솔 애플리케이션의 일부이며 큐를 순차적으로 찾아보고 각 메시지를 읽는 데 예상대로 작동합니다. 플랫 파일에서 문자열 내용을 구문 분석합니다.
그러나 Read () 메서드는 프로그램이 닫힐 때까지 메시지를 잠근 것 같습니다. 모든 메시지를 순차적으로 읽기 위해 루프에서 프로그램을 실행하더라도 프로그램이 완전히 닫힐 때까지 메시지를 '해제'하지 않는 것 같습니다.
Gets and Puts, Dispose, Backout 등을 시도했지만 전체 콘솔 앱의 실행을 중지하는 것 외에는 아무것도 작동하지 않는 것 같습니다.
//Initialize WebMQConnection
WebSphereMQConnection mqRequestConnection = new WebSphereMQConnection(initQMName, initQChannel, initQConnection, initQName, string.Empty, string.Empty);
mqRequestConnection.Open();
mqRequestConnection.Read(message);
도대체 그게 뭐야? 확실히 IBM MQ 클래스 및 메소드가 아닙니다. 그래서 그것은 집에서 자란 수업입니다.
따라서 Read () 메서드는 실제로 '찾아보기'를 수행합니다. 이름이 잘못된 메서드입니다. Read () 메서드에서 MQGET의 MQGMO_LOCK 옵션을 사용하고 있다고 확신합니다.
WebSphereMQConnection 클래스를 제거하고 순수한 IBM MQ .NET 코드를 작성하지 않는 이유는 무엇입니까?
다음은 메시지 잠금없이 큐를 찾아 보는 MQ CS .NET 샘플 프로그램입니다.
using System;
using IBM.WMQ;
/// <summary> Program Name
/// MQTest62B
///
/// Description
/// This C# class will connect to a remote queue manager
/// and get (browse) a message from a queue using a managed .NET environment.
///
/// Sample Command Line Parameters
/// -h 127.0.0.1 -p 1415 -c TEST.CHL -m MQWT1 -q TEST.Q1
/// </summary>
/// <author> Roger Lacroix, Capitalware Inc.
/// </author>
namespace MQTest62
{
public class MQTest62B
{
private System.Collections.Hashtable inParms = null;
private System.String qManager;
private System.String outputQName;
private System.String userID = "tester";
private System.String password = "barney";
/*
* The constructor
*/
public MQTest62B()
: base()
{
}
/// <summary> Make sure the required parameters are present.</summary>
/// <returns> true/false
/// </returns>
private bool allParamsPresent()
{
bool b = inParms.ContainsKey("-h") && inParms.ContainsKey("-p") &&
inParms.ContainsKey("-c") && inParms.ContainsKey("-m") &&
inParms.ContainsKey("-q");
if (b)
{
try
{
System.Int32.Parse((System.String)inParms["-p"]);
}
catch (System.FormatException e)
{
b = false;
}
}
return b;
}
/// <summary> Extract the command-line parameters and initialize the MQ variables.</summary>
/// <param name="args">
/// </param>
/// <throws> IllegalArgumentException </throws>
private void init(System.String[] args)
{
inParms = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable(14));
if (args.Length > 0 && (args.Length % 2) == 0)
{
for (int i = 0; i < args.Length; i += 2)
{
inParms[args[i]] = args[i + 1];
}
}
else
{
throw new System.ArgumentException();
}
if (allParamsPresent())
{
qManager = ((System.String)inParms["-m"]);
outputQName = ((System.String)inParms["-q"]);
// Set up MQ environment
MQEnvironment.Hostname = ((System.String)inParms["-h"]);
MQEnvironment.Channel = ((System.String)inParms["-c"]);
try
{
MQEnvironment.Port = System.Int32.Parse((System.String)inParms["-p"]);
}
catch (System.FormatException e)
{
MQEnvironment.Port = 1414;
}
if (userID != null)
MQEnvironment.UserId = userID;
if (password != null)
MQEnvironment.Password = password;
}
else
{
throw new System.ArgumentException();
}
}
/// <summary> Connect, open queue, read (browse) a message, close queue and disconnect. </summary>
///
private void testReceive()
{
MQQueueManager qMgr = null;
MQQueue inQ = null;
int openOptions = MQC.MQOO_BROWSE + MQC.MQOO_FAIL_IF_QUIESCING;
try
{
qMgr = new MQQueueManager(qManager);
System.Console.Out.WriteLine("MQTest62B successfully connected to " + qManager);
inQ = qMgr.AccessQueue(outputQName, openOptions, null, null, null); // no alternate user id
System.Console.Out.WriteLine("MQTest62B successfully opened " + outputQName);
testLoop(inQ);
}
catch (MQException mqex)
{
System.Console.Out.WriteLine("MQTest62B cc=" + mqex.CompletionCode + " : rc=" + mqex.ReasonCode);
}
catch (System.IO.IOException ioex)
{
System.Console.Out.WriteLine("MQTest62B ioex=" + ioex);
}
finally
{
try
{
if (inQ != null)
inQ.Close();
System.Console.Out.WriteLine("MQTest62B closed: " + outputQName);
}
catch (MQException mqex)
{
System.Console.Out.WriteLine("MQTest62B cc=" + mqex.CompletionCode + " : rc=" + mqex.ReasonCode);
}
try
{
if (qMgr != null)
qMgr.Disconnect();
System.Console.Out.WriteLine("MQTest62B disconnected from " + qManager);
}
catch (MQException mqex)
{
System.Console.Out.WriteLine("MQTest62B cc=" + mqex.CompletionCode + " : rc=" + mqex.ReasonCode);
}
}
}
private void testLoop(MQQueue inQ)
{
bool flag = true;
MQMessage msg = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.Options |= MQC.MQGMO_BROWSE_NEXT | MQC.MQGMO_WAIT | MQC.MQGMO_FAIL_IF_QUIESCING;
gmo.WaitInterval = 500; // 1/2 second wait time or MQC.MQEI_UNLIMITED
while (flag)
{
try
{
msg = new MQMessage();
inQ.Get(msg, gmo);
System.Console.Out.WriteLine("Message Data: " + msg.ReadString(msg.MessageLength));
}
catch (MQException mqex)
{
System.Console.Out.WriteLine("MQTest62B CC=" + mqex.CompletionCode + " : RC=" + mqex.ReasonCode);
if (mqex.Reason == MQC.MQRC_NO_MSG_AVAILABLE)
{
// no meesage - life is good - loop again
}
else
{
flag = false; // severe error - time to exit
}
}
catch (System.IO.IOException ioex)
{
System.Console.Out.WriteLine("MQTest62B ioex=" + ioex);
}
}
}
/// <summary> main line</summary>
/// <param name="args">
/// </param>
// [STAThread]
public static void Main(System.String[] args)
{
MQTest62B write = new MQTest62B();
try
{
write.init(args);
write.testReceive();
}
catch (System.ArgumentException e)
{
System.Console.Out.WriteLine("Usage: MQTest62B -h host -p port -c channel -m QueueManagerName -q QueueName");
System.Environment.Exit(1);
}
catch (MQException e)
{
System.Console.Out.WriteLine(e);
System.Environment.Exit(1);
}
System.Environment.Exit(0);
}
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다