java - JSON, Stomp and ActiveMQ -
java - JSON, Stomp and ActiveMQ -
ok, here's deal. reading this tutorial , documentation activemq website.
on documentation have, under message transformations, sentence:
the transformation message header on send , subscribe messages used instruct activemq transform messages text format of desire. currently, activemq comes transformer can transform xml/json text java objects
and
activemq uses xstream transformation needs. since it's optional dependency have add together broker's classpath putting appropriate jar lib/ folder. additionally, if plan utilize json transformations have add together jettison json parser classpath.
so did this, i've annotated pojo xstreamalias:
@xstreamalias("provapojo") public class provapojo implements serializable { private static final long serialversionuid = 1687248536279612587l; @xstreamalias("fieldone") private int fieldone; @xstreamalias("fieldtwo") private string fieldtwo; public int getfieldone() { homecoming fieldone; } public void setfieldone(int fieldone) { this.fieldone = fieldone; } public string getfieldtwo() { homecoming fieldtwo; } public void setfieldtwo(string fieldtwo) { this.fieldtwo = fieldtwo; } }
and php code (original illustration here):
$body = array( 'provapojo' => array( array('fieldone' => 14), array('fieldtwo' => 'stringa') ) ); $header = array(); $header['transformation'] = 'jms-map-json'; $mapmessage = new stompmessagemap($body, $header); $con->send($queue, $mapmessage);
and listener
@override protected void _onmessage(message message) { if (!(message instanceof objectmessage)) throw new illegalstateexception(); objectmessage objectmessage = (objectmessage) message; seek { if (!(objectmessage.getobject() instanceof blacklisterrecipientbean)) throw new illegalargumentexception( "the message content not instance of " + blacklisterrecipientbean.class.getsimplename()); blacklisterrecipientbean recipient = (blacklisterrecipientbean) objectmessage .getobject(); log.info("_onmessage(message)"); incomingblacklistaddjmstrigger trigger = new incomingblacklistaddjmstrigger(); trigger.setargs(recipient); notifyobservers(trigger); } grab (jmsexception e) { log.error("_onmessage(message) - exception ignored", e); } }
but i'm getting activemqtextmessage. missing?
so apperently problem of activemq version. 1 time switched 5.8.0
worked charm.
java php jms activemq stomp
Comments
Post a Comment