public function publish(string $message, string $routingKey, ?int $flags = null, $attributes = []): void
    {
        if ($this->closed) {
            throw new BadMethodCallException('This Producer object is closed and cannot send any more messages.');
        }
        $this->messages[] = [
            'message' => $message,
            'routingKey' => $routingKey,
            'flags' => $flags,
            'attributes' => $attributes,
        ];
    }