'How to publish raw json message to another application queue?

In my situation, I only need publish message from laravel application to available rabbitmq queue which created in another symfony application. I installed this package https://packagist.org/packages/vladimir-yuldashev/laravel-queue-rabbitmq and follow documentation https://laravel.com/docs/8.x/queues to make laravel work with rabbitmq.

My job class :

<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class HandleLogger implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *

     */
    public function __construct()
    {
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
    }
}

And in controller, I call:

 HandleLogger::dispatch('Some json message')
            ->onConnection('rabbitmq')
            ->onQueue('test-queue');

I just want to publish a raw json message, but when I receive message, it has format:

{
    "uuid": "a6d302bf-74d5-45fa-96a8-ff833101b9ae",
    "displayName": "App\\Jobs\\HandleLogger",
    "job": "Illuminate\\Queue\\CallQueuedHandler@call",
    "maxTries": null,
    "maxExceptions": null,
    "failOnTimeout": false,
    "backoff": null,
    "timeout": null,
    "retryUntil": null,
    "data": {
        "commandName": "App\\Jobs\\HandleLogger",
        "command": "O:21:\"App\\Jobs\\HandleLogger\":10:{s:3:\"job\";N;s:10:\"connection\";s:8:\"rabbitmq\";s:5:\"queue\";s:10:\"test-queue\";s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:19:\"chainCatchCallbacks\";N;s:5:\"delay\";N;s:11:\"afterCommit\";N;s:10:\"middleware\";a:0:{}s:7:\"chained\";a:0:{}}"
    },
    "id": "f58793de-0623-4972-a0f2-c6290df7fb28"
}

I could not found any answers for it.

Edit: In laravel documentation, it only gives an example like pass a model in constructor arguments. So I tried pass argument as string type like

/**
 * @var string
 */
 protected $payLoad;
  
 public function __construct(string $payLoad)
 {
    $this->payLoad = $payLoad;
 }

but it not effects :

{
    "uuid": "b402c214-9a75-4968-b628-2972dfab9edb",
    "displayName": "App\\Jobs\\HandleLogger",
    "job": "Illuminate\\Queue\\CallQueuedHandler@call",
    "maxTries": null,
    "maxExceptions": null,
    "failOnTimeout": false,
    "backoff": null,
    "timeout": null,
    "retryUntil": null,
    "data": {
        "commandName": "App\\Jobs\\HandleLogger",
        "command": "O:21:\"App\\Jobs\\HandleLogger\":11:{s:10:\"\u0000*\u0000payLoad\";s:17:\"Some json message\";s:3:\"job\";N;s:10:\"connection\";s:8:\"rabbitmq\";s:5:\"queue\";s:10:\"test-queue\";s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:19:\"chainCatchCallbacks\";N;s:5:\"delay\";N;s:11:\"afterCommit\";N;s:10:\"middleware\";a:0:{}s:7:\"chained\";a:0:{}}"
    },
    "id": "81d1a439-b120-4187-9dc6-0b20fe2d3a66"
}


Solution 1:[1]

It works for me, no need Laravel Job class :

$queueManager = app('queue');
$queue = $queueManager->connection('rabbitmq');
$queue->pushRaw('json message', 'queue_name');

Solution 2:[2]

app('queue')->connection('database')->pushRaw(json_encode($user), 'provisioning_users');

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nguyen Nhut Tien
Solution 2 Henry Ecker