src/Publisher/Publisher.php
public function publish($message, $routingKey = null, $flags = AMQP_NOPARAM, array $attributes = [])
    {
        $hasEventDispatcher = null !== $this->eventDispatcher;

        if(!empty($this->routingKeyPrefix)){
            $routingKey = $this->routingKeyPrefix . $routingKey;
        }

        if (!$this->isInitialized()) {
            $this->initialize();
        }

        if (true === $hasEventDispatcher) {
            $event = new PublisherEvent(
                $message,
                $routingKey,
                $flags,
                $attributes,
                $this->exchange
            );
        }

        try {
            if (true === $hasEventDispatcher) {
                $this->eventDispatcher->dispatch(PublisherEvents::PRE_PUBLISH, $event);

                $result = $this->exchange->getWrappedExchange()->publish(
                    $event->getMessage(),
                    $event->getRoutingKey(),
                    $event->getFlags(),
                    $event->getAttributes()
                );
            } else {
                $result = $this->exchange->getWrappedExchange()->publish(
                    $message,
                    $routingKey,
                    $flags,
                    $attributes
                );
            }

            if (!$result) {
                if (true === $hasEventDispatcher) {
                    $this->eventDispatcher->dispatch(PublisherEvents::FAIL_PUBLISH, new FailedPublisherEvent($event, null, $this));
                }
            } else {
                if (true === $hasEventDispatcher) {
                    $this->eventDispatcher->dispatch(PublisherEvents::SUCCESS_PUBLISH, new SuccessPublisherEvent($event));
                }
            }
        } catch (\Exception $e) {
            if (true === $hasEventDispatcher) {
                $this->eventDispatcher->dispatch(PublisherEvents::FAIL_PUBLISH, new FailedPublisherEvent($event, $e, $this));
            }

            throw $e;
        }

        return $result;
    }
public function publish($message, $routingKey = null, $flags = AMQP_NOPARAM, array $attributes = [])
    {
        $hasEventDispatcher = null !== $this->eventDispatcher;

        if(!empty($this->routingKeyPrefix)){
            $routingKey = $this->routingKeyPrefix . $routingKey;
        }

        if (!$this->isInitialized()) {
            $this->initialize();
        }

        if (true === $hasEventDispatcher) {
            $event = new PublisherEvent(
                $message,
                $routingKey,
                $flags,
                $attributes,
                $this->exchange
            );
        }

        try {
            if (true === $hasEventDispatcher) {
                $this->eventDispatcher->dispatch(PublisherEvents::PRE_PUBLISH, $event);

                $result = $this->exchange->getWrappedExchange()->publish(
                    $event->getMessage(),
                    $event->getRoutingKey(),
                    $event->getFlags(),
                    $event->getAttributes()
                );
            } else {
                $result = $this->exchange->getWrappedExchange()->publish(
                    $message,
                    $routingKey,
                    $flags,
                    $attributes
                );
            }

            if (!$result) {
                if (true === $hasEventDispatcher) {
                    $this->eventDispatcher->dispatch(PublisherEvents::FAIL_PUBLISH, new FailedPublisherEvent($event, null, $this));
                }
            } else {
                if (true === $hasEventDispatcher) {
                    $this->eventDispatcher->dispatch(PublisherEvents::SUCCESS_PUBLISH, new SuccessPublisherEvent($event));
                }
            }
        } catch (\Exception $e) {
            if (true === $hasEventDispatcher) {
                $this->eventDispatcher->dispatch(PublisherEvents::FAIL_PUBLISH, new FailedPublisherEvent($event, $e, $this));
            }

            throw $e;
        }

        return $result;
    }
@param string $message
@param null   $routingKeyArgument::type(Publisher::class)
@param int    $flags
@param array  $attributes

@throws \Exception

@return bool