none
Pooling of custom WCF channel RRS feed

  • Question

  • We have developed a custom WCF channel which communicates via IBM Websphere MQ.

    We have created a channel factory:
     public class MqChannelFactory : ChannelFactoryBase<IRequestChannel>
    Which returns instances of our channel:
    public class MqRequestChannel : ChannelBase, IRequestChannel
    

    Connecting to the IBM MQ queue manager is an expensive operation.  Currently, we do this in Channel.OnOpen(). 

    Following the guidelines for correct use of channels, we are callign ChannelFactory.CreateChannel() each time we require a channel, sending the message, then calling Channel.Close().

    Our assumption was, that the ChannelFactory performed pooling of channels, so that when Channel.Close() was called, the channel was not actually closed but rather returned to the pool.  But, everytime we call ChannelFactory.CreateChannel, a new channel is being instantiated, and when the request is sent, the expensive channel opening is performed.

    So, the question:  What is the best approach to prevent the channel being opened on every request? Is there anyway through configuration to specify that channel pooling should take place?  Should we be implementing our own channel pooling in our ChannelFactory?  Should we just keep our channel open for the life of the application, sending all requests through it? Should we perform the expensive operation (connecting to the queue manager) in the channel factory , which we cache for the life of the application?

    Wednesday, January 13, 2010 1:12 AM

Answers

  • Hi Michael.  The ChannelFactory does not pool / reuse channels.  However, it will maintain a list of the channels created so that closing  / aboorting the factory will do the same to any channels create through it.

    To reuse channels, I reccomened implementing caching them yourself.  In your implementation, when placing or removing from your cache, you may want to check the state of the channels so that user's of the channels don't get faulted / closed channels.

    Cheers,
      Lars
    Tuesday, January 19, 2010 1:21 AM

All replies

  • Hi Michael.  The ChannelFactory does not pool / reuse channels.  However, it will maintain a list of the channels created so that closing  / aboorting the factory will do the same to any channels create through it.

    To reuse channels, I reccomened implementing caching them yourself.  In your implementation, when placing or removing from your cache, you may want to check the state of the channels so that user's of the channels don't get faulted / closed channels.

    Cheers,
      Lars
    Tuesday, January 19, 2010 1:21 AM
  • Host Integration Server 2009 and IBM WebSphere MQ 7 client now both ship with a WebSphere MQ transport. Maybe you don't have to custom build this then.
    Thursday, March 4, 2010 2:29 PM