java - Client acknowledgement in JMS -
can know client acknowledgement in jms.
right using auto_acknowledgement
acknowledgement purpose.
i know how change auto_acknowledgement
client_acknowledgement
here code.
public connection openconnection() throws jmsexception { connectionfactory connectionfactory = jmsconfiguration .connectionfactory(); connection conn = connectionfactory.createconnection(); return conn; } /** * * @param queuedata * @param queuename * @throws jmsexception * @throws datacaptureexception */ public void sendmessage(string queuedata, string queuename) throws jmsexception, datacaptureexception { connection connection = null; try { connection = openconnection(); session session = connection.createsession(false, session.auto_acknowledge); destination destination = session.createqueue(queuename); messageproducer producer = session.createproducer(destination); producer.setdeliverymode(deliverymode.non_persistent); message message = session.createtextmessage(queuedata); producer.send(message); session.close(); } catch (jmsexception e) { throw new datacaptureexception(e.getmessage(), e.getcause()); } { if (connection != null) { connection.close(); } } } /** * * @param queuename * @return * @throws jmsexception * @throws datacaptureexception */ public string receivemessage(string queuename) throws jmsexception, datacaptureexception { connection connection = null; string queuemessage = null; try { connection = openconnection(); connection.start(); session session = connection.createsession(false, session.auto_acknowledge); messageconsumer consumer = session.createconsumer(session .createqueue(queuename)); message message = consumer.receive(1000); consumer.close(); if (null != message) { queuemessage = ((textmessage) message).gettext(); } session.close(); } catch (jmsexception e) { throw new datacaptureexception(e.getmessage(), e.getcause()); } { if (connection != null) { connection.close(); } } return queuemessage; }
can let me know how change client_acknowledgement
, how verify it.
you need change creation of session client_acknowledge:
session session = connection.createsession(false, session.client_acknowledge);
then have acknowledge messages in code:
message.acknowledge();
you should acknowledge message once happy deleted. verify works see if message still exists on destination or not.
Comments
Post a Comment