Vinelab / bowler

RabbitMQ wrapper for Laravel
MIT License
45 stars 9 forks source link

Corrupted JSON response when producing a message #46

Closed snezhkoigor closed 5 years ago

snezhkoigor commented 5 years ago

Hi. I have some problem with row 123 in file Producer.php

echo ' [x] Data Package Sent to ', $this->exchangeName, ' Exchange!', "\n";

When I'm trying send something to frontend after $producer->send(...) every time I have extra text in response.

My case - I send message to RabbitMQ, generate uniq channel id and send channel to frontend.

snezhkoigor commented 5 years ago

`

$job = new OptimizerPositioningRequestJob();

$this->dispatch($job);

    return response()->json([
        'data' => [
            'channel' => $channel,
            'reference_points' => $through_cities,
            'way_points' => $way_points
        ]
    ], Response::HTTP_OK);

`

In OptimizerPositioningRequestJob I send message, so response()->json has extra text

snezhkoigor commented 5 years ago

Now I've redeclared Producer class with method send

KinaneD commented 5 years ago

Sure, whenever a message is sent to the queue, a notification is printed in terminal. That is being returned along with your JSON response. You should surround the function to send the message by ob_start() and ob_end_clean() to discard the output.

ob_start();
$producer->send($exchange, $payload);
$ob_end_clean();

On a side note, please change the issue title to reflect what the actual issue is; to improve its discoverability for others.

Thanks.

snezhkoigor commented 5 years ago

Thank you so much!