Is it legal and safe to send a message to another queue from a consumer of current queue?
public void onMessage(){
//save to db
Order o=myservice.create(order);
Object o=rabbitTemplate.convertSendAndReceive(queue2,orderId);
}
I think in this case consumer of the second queue may not see the saved order because the transaction will be committed only after onMessage method exits.
And is it safe and legal to send messages from consumers?
Yes, it's perfectly legal and safe, looking from the rabbitmq or amqp side.
But is it safe for the consistency of the data that your business application is handling, that's another story. If consumer A receives message M, extracts some data from it to S for DB writing (for example) and in the same time forwards message M to consumer B that upon receiving needs to write data to DB, but this data is depending on S, then what will happen? Well, chances are random and this is known as race condition - in this case, A is racing the broker - it needs to write S to DB before B receives the message M.
Best way to avoid the race is, well, to avoid the race. Have A forward the message only after it has finished "setting up the play" for the other consumers.