java - Message Driven Bean with a Datasource -


my question how configure ejb 3.0 style message driven bean use configured jms datasource in jboss.

for example, mdb looks like:

@messagedriven(mappedname = "examplemdb", activationconfig = {          @activationconfigproperty(propertyname = "destinationtype", propertyvalue = "javax.jms.topic"),         @activationconfigproperty(propertyname = "destination", propertyvalue = "mytopic"),         @activationconfigproperty(propertyname = "channel", propertyvalue = "mychannel"),  }) @resourceadapter(value = "wmq.jmsra.rar") @transactionattribute(transactionattributetype.not_supported) @transactionmanagement(transactionmanagementtype.bean) public class mymdb implements messagelistener {  ..... } 

but bean attached given jms datasource ( in case of jboss 4.2.2 in deploy/jms/jms-ds.xml). perhaps not possible worth asking.

if understood problem correctly, mymdb listens topic on weblogic, , want use additional jms destination provided jboss, defined in deployed configuration file , identified jndi name (by default, deploy/jms/jms-ds.xml contains configuration jms provider , connection factories -- no data sources).

the easiest way let container inject jms destination , connection factory via jndi name (in jboss jms destinations configured deploying xxx-service.xml files). on startup can initialize connection, , perform cleanup mdb released.

the following examples shows injection (@resource) , resource managemend (@postconstruct , @predestroy). jms connection , destination used in usejmsdestination(string) send text message.

public class mymdb implements messagelistener {      @resource(mappedname = "queue/yourqueuename") // can topic     private queue targetdestination;      @resource(mappedname = "queueconnectionfactory") // or connectionfactory     private queueconnectionfactory factory;      private connection conn;      public void onmessage(message m) {         // parse message , need         ...         // message , jboss jms destination         usejmsdestination(messagestring);          }      private void usejmsdestination(string text) {         session session = null;         messageproducer producer = null;          try {             session = conn.createsession(true, session.auto_acknowledge);             producer = session.createproducer(targetdestination);             textmessage msg = session.createtextmessage(text);             producer.send(msg);         } catch (jmsexception e) {             throw new runtimeexception(e);         } {             try {                 if (producer != null) {                     producer.close();                 }                 if (session != null) {                     session.close();                 }             } catch (jmsexception e) {                 // handle error, should non-fatal, message sent.             }         }     }       @postconstruct     void init() {         initconnection();         // other initialization logic         ...     }      @predestroy     void cleanup() {         closeconnection();         // other cleanup logic         ...     }      private void initconnection() {         try {             conn = factory.createconnection();         } catch (jmsexception e) {             throw new runtimeexception("could not initialize connection", e);         }     }      private void closeconnection() {         try {             conn.close();         } catch (jmsexception e) {             // handle error, should non-fatal, connection being closed         }     } } 

i hope can you.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -