예제 #1
0
 def __init__(self,
              mqManager,
              mqURI,
              consumerId,
              callback=generateDefaultCallback()):
     self._connectionManager = mqManager
     self._mqURI = mqURI
     self._destination = getDestinationAddress(self._mqURI)
     self._id = consumerId
     self._callback = callback
     self.log = gLogger.getSubLogger(self.__class__.__name__)
     #subscribing to connection
     result = self._connectionManager.getConnector(getMQService(
         self._mqURI))
     if result['OK']:
         connector = result['Value']
         if connector:
             result = connector.subscribe(
                 parameters={
                     'messengerId': self._id,
                     'callback': callback,
                     'destination': self._destination
                 })
             if not result['OK']:
                 self.log.error('Failed to subscribe the consumer:' +
                                self._id)
         else:
             self.log.error(
                 'Failed to initialize MQConsumer! No MQConnector!')
     else:
         self.log.error('Failed to get MQConnector!')
예제 #2
0
def createConsumer( mqURI, callback = generateDefaultCallback() ):
  """ Function creates MQConsumer. All parameters are taken
      from the Configuration Service based on the mqURI
      value.
  Args:
    mqURI(str):Pseudo URI identifing MQ service. It has the following format
              mqConnection::DestinationType::DestinationName
              e.g. blabla.cern.ch::Queue::MyQueue1
    callback: callback function that can be used to process the incoming messages
  Returns:
    S_OK/S_ERROR: with the consumer object in S_OK.
  """
  result = _setupConnection( mqURI = mqURI, mType = "consumer" )
  if not result['OK']:
    gLogger.error( 'Failed to createConsumer:', result['Message'] )
    return result
  return S_OK( MQConsumer( mqManager = connectionManager, mqURI  = mqURI, consumerId = result['Value'], callback = callback ) )
예제 #3
0
 def __init__( self, mqManager, mqURI, consumerId, callback = generateDefaultCallback() ):
   self._connectionManager = mqManager
   self._mqURI = mqURI
   self._destination = getDestinationAddress( self._mqURI )
   self._id = consumerId
   self._callback = callback
   self.log = gLogger.getSubLogger( self.__class__.__name__ )
   #subscribing to connection
   result =  self._connectionManager.getConnector( getMQService( self._mqURI ) )
   if result['OK']:
     connector = result['Value']
     if connector:
       result = connector.subscribe( parameters = {'messengerId':self._id, 'callback':callback, 'destination':self._destination} )
       if not result['OK']:
         self.log.error( 'Failed to subscribe the consumer:' + self._id )
     else:
       self.log.error( 'Failed to initialize MQConsumer! No MQConnector!' )
   else:
     self.log.error( 'Failed to get MQConnector!' )
예제 #4
0
def createConsumer(mqURI, callback=generateDefaultCallback()):
    """ Function creates MQConsumer. All parameters are taken
      from the Configuration Service based on the mqURI
      value.
  Args:
    mqURI(str):Pseudo URI identifing MQ service. It has the following format
              mqConnection::DestinationType::DestinationName
              e.g. blabla.cern.ch::Queue::MyQueue1
    callback: callback function that can be used to process the incoming messages
  Returns:
    S_OK/S_ERROR: with the consumer object in S_OK.
  """
    result = _setupConnection(mqURI=mqURI, mType="consumer")
    if not result['OK']:
        gLogger.error('Failed to createConsumer:', result['Message'])
        return result
    return S_OK(
        MQConsumer(mqManager=connectionManager,
                   mqURI=mqURI,
                   consumerId=result['Value'],
                   callback=callback))