我定义多个主机名多实例队列管理器为我改变队列管理器的单个实例多实例队列管理器的麻烦。 现有的主机在web.config中定义
<QueueConfigurationSection>
<QueueConfiguration>
<add name="SomeQueueHandler" queueManager="QM1" host="99.99.99.01" port="12345" requestQueue="A.B.REQUEST" service="FLATFILE" responseQueue="B.A.RESPONSE" internalResponseQueue="B.A.INTERNAL" channel="A.SVC.SVRCONN" binding="SOAP11TcpBinding" endPoint="net.tcp://localhost:808/Bus/SomeServiceBus.svc/SOAP11" />
</QueueConfiguration>
</QueueConfigurationSection>
连接在这里定义
public List<QueueHandler> Queues
{
get
{
if (_queues == null)
_queues = new List<QueueHandler>();
if (_queues.Count == 0 && _queueConfiguration != null)
{
//create queue handlers from configuration provided
foreach (QueueConfigurationElement element in _queueConfiguration)
{
// Using a different connection factory for each queue
XMSFactoryFactory factory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
IConnectionFactory connectionProperties = factory.CreateConnectionFactory();
connectionProperties.SetStringProperty(XMSC.WMQ_HOST_NAME, element.Host);
connectionProperties.SetIntProperty(XMSC.WMQ_PORT, element.Port);
connectionProperties.SetStringProperty(XMSC.WMQ_CHANNEL, element.Channel);
connectionProperties.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
connectionProperties.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1);
connectionProperties.SetBooleanProperty(XMSC.WMQ_USE_CONNECTION_POOLING, true);
var queue = new QueueHandler(element.Name, connectionProperties);
_queues.Add(queue);
}
}
return new List<QueueHandler>(_queues);
}
}
QueueHandler:
public QueueHandler(string handlerName, IConnectionFactory mqConnectionFactory)
{
_connectionProperties = mqConnectionFactory;
var queueConfigurationSection = ConfigurationManager.GetSection(QueueConfigurationSection.SectionName) as QueueConfigurationSection;
if (queueConfigurationSection != null)
{
if (queueConfigurationSection.QueueConfigurationCollection.Cast<QueueConfigurationElement>().Any(qc => qc.Name == handlerName))
{
var element = queueConfigurationSection.QueueConfigurationCollection.Cast<QueueConfigurationElement>().First(qc => qc.Name == handlerName);
_name = element.Name;
_serviceType = element.DestinationService;
_queueManagerName = element.QueueManager;
_channel = element.Channel;
_requestQueueName = element.RequestQueue;
_responseQueueName = element.ResponseQueue;
_internalResponseQueueName = element.InternalResponseQueue;
_port = element.Port;
_host = element.Host;
//set up binding configuraion
EndpointType bindingEnum;
if (System.Enum.TryParse(element.Binding, out bindingEnum))
{
_messageType = bindingEnum;
switch (bindingEnum)
{
case EndpointType.FlatFileTcpBinding:
//message received from the request queue is plain text - by configuration
_dvsBinding = EndpointHelper.CreateFlatFileTCPBinding();
break;
// ...
default:
//unsupported endpoint configuration
throw new Exception("Unsupported binding configuration");
}
}
//create endpoint address
_endPointAddress = new EndpointAddress(element.EndPoint);
}
}
}
和主机名和端口还限定在在SendNewMessage方法相同类...
try
{
if (port != 0)
MQEnvironment.Port = port;
if (host != ".")
MQEnvironment.Hostname = host;
if (channel != ".")
MQEnvironment.Channel = channel;
hMgr = new MQQueueManager(manager);
}
所以,我怎么设置MQEnvironment.Hostname备用主机?