AppserverIo\Appserver\MessageQueue\MessageQueue::attach PHP Method

attach() public method

Attach a new message to the queue.
public attach ( AppserverIo\Psr\Pms\MessageInterface $message ) : void
$message AppserverIo\Psr\Pms\MessageInterface The messsage to be attached to the queue
return void
    public function attach(MessageInterface $message)
    {
        // force handling the timer tasks now
        $this->synchronized(function (MessageQueue $self, MessageInterface $m) {
            // create a unique identifier for the priority
            $priority = $this->uniqueWorkerName($m->getPriority());
            // load the worker for the message's priority
            if (isset($self->workers[$priority])) {
                // attach the message
                $self->messages[$m->getMessageId()] = $m;
                // store the job-ID and the PK of the message => necessary to load the message later
                $jobWrapper = new \stdClass();
                $jobWrapper->jobId = $m->getMessageId();
                $jobWrapper->messageId = $m->getMessageId();
                // attach the job to the worker
                $self->workers[$priority]->attach($jobWrapper);
            }
        }, $this, $message);
    }