Created
September 25, 2013 09:24
-
-
Save djfr/6697180 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Opens this queue. Supports listening and writing options, if setup | |
/// for listening it will do browse and not really reads from the queue | |
/// as messages arrive to the queue. | |
/// </summary> | |
/// <param name="reading">True if we want to read from this queue, false otherwise.</param> | |
/// <param name="writing">True if we want to write to this queue, false otherwise.</param> | |
/// <returns>The Observable where all the messages read from this queue will appear.</returns> | |
public IObservable<IServiceMessage> OpenConnection(bool reading = true, bool writing = false) | |
{ | |
// create the properties HashTable | |
var mqProperties = new Hashtable | |
{ | |
{ MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED }, | |
{ MQC.HOST_NAME_PROPERTY, ConfigurationProvider.MQMessageListenerHostName }, | |
{ MQC.PORT_PROPERTY, ConfigurationProvider.MQMessageListenerPortNumeric }, | |
{ MQC.CHANNEL_PROPERTY, ConfigurationProvider.MQMessageListenerChannelName } | |
}; | |
// create the queue manager | |
_queueManager = new MQQueueManager(ConfigurationProvider.MQMessageListenerQueueManagerName, mqProperties); | |
// deal with the queue open options | |
var openOptions = MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING; | |
if (reading) | |
{ | |
openOptions += MQC.MQOO_BROWSE; | |
} | |
if (writing) | |
{ | |
openOptions += MQC.MQOO_OUTPUT; | |
} | |
// create and start the queue, check for potential bad queue names | |
try | |
{ | |
Queue = _queueManager.AccessQueue(QueueName, openOptions); | |
} | |
catch (MQException ex) | |
{ | |
if (ex.ReasonCode == 2085) | |
{ | |
throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture, "Wrong Queue name: {0}", QueueName)); | |
} | |
throw; | |
} | |
if (reading) | |
{ | |
StartListening(); | |
} | |
return Stream.AsObservable(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment