ANKITA GUPTA
ANKITA GUPTA

Reputation: 21

How to send complete object as message from producer to consumer in php rabbitmq

How to send complete object having some private properties as message from producer to consumer in php rabbitmq

Upvotes: 0

Views: 1205

Answers (2)

Dhayal Ram
Dhayal Ram

Reputation: 342

It's better to have a function inside the object which returns the particular properties which you need to send a message to json_encode

For Example

class Cycle{
    private $name;
    private $notSending;
    public $type;

    public function getProducerMessage(){
        return json_encode( [ 'name' => $this->name, 'type' => $this->type ] );
    }
}

Upvotes: 1

Derick Bailey
Derick Bailey

Reputation: 72868

You have to convert the object to a text based data structure, typically a JSON object. Something like json_encode would be a good place to start

Upvotes: 1

Related Questions