connect = jmsConnectionFactory.createConnection(); session = connect.createSession(false, Session.DUPS_OK_ACKNOWLEDGE); producer = session.createProducer(queue); // ★ Queue名の指定 // create a JMS message and send it ObjectMessage objMsg = session.createObjectMessage(message); // set message selector objMsg.setStringProperty("MyFilterKey", "MyFilterValue"); // ★ ここでフィルターをkey, valueで指定(値は任意) producer.send(objMsg);
@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), // ★ 接続先送信タイプの指定(Queue or Topic) @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/myjmsqueue"), // ★ Queue名の指定。WildFlyからはpropertyNameは、destinationTypeに変更っぽい @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "MyFilterKey = 'MyFilterValue'") }) // ★ ここがフィルター部分 public class MyMDB extends implements MessageListener {
@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/myjmsqueue"), @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "MyFilterKey = 'MyFilterValue'"), @ActivationConfigProperty(propertyName = "transactionTimeout", propertyValue = 960) }) public class IdentifyPrepareTemplateEventReceiver extends AbstractEventReceiver
JBoss を含むほとんどのアプリケーションサーバーでは、プール内の MDB の数を設定できます。 ejb3-interceptors-aop.xml ファイル内の MaxPoolSize パラメーターが、作成されるセッションまたはコンシューマーの数に影響を持たないことを理解することが重要です。 これは、リソースアダプター実装がアプリケーションサーバー MDB 実装を認識しないためです。 たとえば、MDB MaxPoolSize を 1 に設定すると、15 個のセッションまたはコンシューマーが作成されます (15 がデフォルト値)。 作成されるセッションまたはコンシューマーの数を制限するには、リソースアダプターまたは MDBのActivationConfigProperty アノテーションで maxSession パラメーターを設定します。 @MessageDriven(name = "MDBMessageSendTxExample", activationConfig = { @ActivationConfigProperty (propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty (propertyName = "destination", propertyValue = "queue/testQueue"), @ActivationConfigProperty (propertyName = "maxSession", propertyValue = "1") }) @TransactionManagement(value= TransactionManagementType.CONTAINER) @TransactionAttribute(value= TransactionAttributeType.REQUIRED) public class MyMDB implements MessageListener { ....}