AppserverIo\Appserver\MessageQueue\QueueManager::createSenderForQueue PHP Method

createSenderForQueue() public method

Return a new sender for the message queue with the passed lookup name.
public createSenderForQueue ( string $lookupName, string $sessionId = null ) : AppserverIo\Messaging\QueueSender
$lookupName string The lookup name of the queue to return a sender for
$sessionId string The session-ID to be passed to the queue session
return AppserverIo\Messaging\QueueSender The sender instance
    public function createSenderForQueue($lookupName, $sessionId = null)
    {
        // load the application name
        $application = $this->getApplication();
        $applicationName = $application->getName();
        $webappPath = $application->getWebappPath();
        // initialize the variable for the properties
        $properties = null;
        // load the configuration base directory
        if ($baseDirectory = $this->getManagerSettings()->getBaseDirectory()) {
            // look for naming context properties in the manager's base directory
            $propertiesFile = DirectoryKeys::realpath(sprintf('%s/%s/%s', $webappPath, $baseDirectory, QueueManagerSettingsInterface::CONFIGURATION_FILE));
            // load the properties from the configuration file
            if (file_exists($propertiesFile)) {
                $properties = Properties::create()->load($propertiesFile);
            }
        }
        // initialize and return the sender
        $queue = \AppserverIo\Messaging\MessageQueue::createQueue($lookupName);
        $connection = \AppserverIo\Messaging\QueueConnectionFactory::createQueueConnection($applicationName, $properties);
        $session = $connection->createQueueSession();
        return $session->createSender($queue);
    }