Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repeated Acknowledgements with SetBody() #154

Closed
rayanimesh opened this issue Mar 29, 2014 · 3 comments
Closed

Repeated Acknowledgements with SetBody() #154

rayanimesh opened this issue Mar 29, 2014 · 3 comments

Comments

@rayanimesh
Copy link

I checked issues list and didn't found related issue in list.

I am opening Channel in confirm_select() mode and then publishing a single message multiple times with different message bodies using setBody(). But I am getting acknowledgements with last sent message body.

Sample Code:

$msg = new AMQPMessage($msg_body);
$i       = 1;
while($i<11)
{
       $msg_body = $i++;
       $msg->setBody($msg_body);
       $ch->basic_publish($msg, $exchange);
}
$ch->wait_for_pending_acks();

It will provide me 11 acknowledgements with message body 11.
We are storing message into published_messages array when we publish a message into exchange.

     $this->published_messages[$this->next_delivery_tag] = $msg; 

When we use setBody() function to change body of message it is changing message body of published_message array. (Due to by reference objects passing in PHP5 which keeps reference of message body).

Cloning $msg and then saving into published_message worked for me.

Can you look into this?

@videlalvaro
Copy link
Collaborator

The setBody() thingie is there mostly if you need to publish as fast as possible, but in your case I would just create a new instance AMQPMessage instance.

@rayanimesh
Copy link
Author

Hi,
Thanks for quick reply.
I want to achieve high performance so I don't want to create a new AMQPMessage instance each time. I tried creating new message instance each time but it slowed performance by 100% (Reusing takes ~2ms while creating new instance takes ~4ms).

But reusing message body leads to repeated acknowledgements as I mentioned. And we can fix it, by storing cloned message into published_message array.

     $this->published_messages[$this->next_delivery_tag] =  clone($msg); 

Or am I missing something?

@rayanimesh rayanimesh changed the title Repeated Acknowledgements Repeated Acknowledgements with SetBody() Mar 29, 2014
@lukebakken lukebakken added this to the 2.7.1 milestone Jan 17, 2018
@lukebakken lukebakken assigned lukebakken and unassigned lukebakken Jan 17, 2018
@lukebakken lukebakken modified the milestones: 2.7.1, 2.7.2 Jan 29, 2018
@lukebakken lukebakken removed this from the 2.7.2 milestone Feb 10, 2018
@lukebakken
Copy link
Collaborator

Closing due to inactivity, and due to workarounds in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants