2012-03-26 8 views
0

私は恒久サブスクライバを使用してトピックを作成しようとしています。無Jboss 5のトピックの永続サブスクライバを作成するには?

@MessageDriven(activationConfig = { 
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"), 
@ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/durableTopic"), 
@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable") }) 
public class DurableSubscriberOne implements MessageListener { 
// ... 

しかし、私は、JMXコンソールまたは管理コンソールを入力したときに、私は一つの非永続サブスクリプションとして、私のトピックを参照してください:私は私の基本的なトピックだ:

<?xml version="1.0" encoding="UTF-8"?> 
<server> 
    <mbean code="org.jboss.jms.server.destination.TopicService" name="jboss.messaging.destination:service=Topic,name=durableTopic" xmbean-dd="xmdesc/Topic-xmbean.xml"> 
    <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends> 
    <depends>jboss.messaging:service=PostOffice</depends> 
</mbean> 
</server> 

をそして私は私のサブスクライブMDBを得ました恒久サブスクリプション。

私はいくつかの誤植や小さな間違いをしていますか、それよりも難しいですか?私はJBoss 5.1.0.GAを使用しています。

+0

は正確に同じ問題を抱えています。それはログ 'durable = true'でも言えますが、JMXコンソールでは私はNonDurableSubscriptionしか持っていません。 –

答えて

1

は同じ問題を抱えていたので、私は最終的にMDBが2以上@ActivationConfigPropertyを追加することにより、耐久性のあるサブスクリプションを作成するために管理:

@ActivationConfigProperty(propertyName = "subscriptionName", propertyValue ="SomeSubscriptionName") 
@ActivationConfigProperty(propertyName = "clientId", propertyValue ="SomeClientId") 
+0

現在、私たちのシステム仕様はわずかに変更されていますが、これは大丈夫ですが、今すぐトピックに接続するjbossブリッジがあり、2つの属性が必要です: '<属性名=" SubName ">サブ名 <属性名= "ClientID"> clientId ' だから私はMDBにも同じことが必要だと考えています(マニュアルでは、subscriptionNameはデフォルトでMDBのjndi名、jarの名前、その他のものから作成されているようです)。 – r3mbol

0

本当に間違いはありません。単に私のために働くコード。私は自分のコードサンプルと参照用のスクリーンショットを含めています。

package com.jboss.example; 

import javax.ejb.ActivationConfigProperty; 
import javax.ejb.MessageDriven; 
import javax.jms.Message; 
import javax.jms.MessageListener; 

/** 
* Message-Driven Bean implementation class for: DurableMessageListener 
* 
*/ 
@MessageDriven(activationConfig = { 
     @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"), 
     @ActivationConfigProperty(propertyName = "destination", propertyValue = "topic/durableTopic"), 
     @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable") }) 
//, mappedName = "durableTopic") 
public class DurableMessageListener implements MessageListener { 

    /** 
    * Default constructor. 
    */ 
    public DurableMessageListener() { 
     // TODO Auto-generated constructor stub 
    } 

    /** 
    * @see MessageListener#onMessage(Message) 
    */ 
    public void onMessage(Message message) { 
     // TODO Auto-generated method stub 
     System.out.println("Received Message " + message); 
    } 

} 

トピックサブスクライバサンプル

package com.jboss.example; 

import java.util.Properties; 

import javax.jms.JMSException; 
import javax.jms.Message; 
import javax.jms.Topic; 
import javax.jms.TopicConnection; 
import javax.jms.TopicConnectionFactory; 
import javax.jms.TopicSession; 
import javax.jms.TopicSubscriber; 
import javax.naming.InitialContext; 
import javax.naming.NamingException; 

public class DurableTopicSubscriber { 
    TopicConnection conn = null; 
    TopicSession session = null; 
    Topic topic = null; 

    public void setupPubSub() throws JMSException, NamingException { 

     Properties env = new Properties(); 
     env.setProperty("java.naming.factory.initial", 
       "org.jnp.interfaces.NamingContextFactory"); 
     env.setProperty("java.naming.factory.url.pkgs", 
       "org.jboss.naming:org.jnp.interfaces"); 
     env.setProperty("java.naming.provider.url", "jnp://localhost:1099"); 
     InitialContext iniCtx = new InitialContext(env); 
     Object tmp = iniCtx.lookup("ConnectionFactory"); 

     TopicConnectionFactory tcf = (TopicConnectionFactory) tmp; 
     conn = tcf.createTopicConnection("guest", "guest"); 
     conn.setClientID("Dirabla"); 
     topic = (Topic) iniCtx.lookup("topic/durableTopic"); 

     session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); 
     conn.start(); 
    } 

    public void recvSync() throws JMSException, NamingException { 
     System.out.println("Begin recvSync"); 
     // Setup the pub/sub connection, session 
     setupPubSub(); 
     // Wait upto 5 seconds for the message 
     TopicSubscriber recv = session.createSubscriber(topic); 
     //TopicSubscriber recv = session.createDurableSubscriber(topic, "durableTopicName"); 
     Message msg = recv.receive(5000); 
     while (msg != null) { 
      System.out.println("DurableTopicClient.recv, msgt=" + msg); 
      msg = recv.receive(5000); 
     } 
    } 

    public void stop() throws JMSException { 
     conn.stop(); 
     session.close(); 
     conn.close(); 
    } 

    public static void main(String args[]) throws Exception { 
     System.out.println("Begin DurableTopicRecvClient, now=" 
       + System.currentTimeMillis()); 
     DurableTopicSubscriber client = new DurableTopicSubscriber(); 
     client.recvSync(); 
     client.stop(); 
     System.out.println("End DurableTopicRecvClient"); 
     System.exit(0); 
    } 

} 

トピックサンプル出版

package com.jboss.example; 

import java.util.Properties; 

import javax.jms.JMSException; 
import javax.jms.Message; 
import javax.jms.Topic; 
import javax.jms.TopicConnection; 
import javax.jms.TopicConnectionFactory; 
import javax.jms.TopicPublisher; 
import javax.jms.TopicSession; 
import javax.naming.InitialContext; 
import javax.naming.NamingException; 

public class DurableTopicPublisher { 
    TopicConnection conn = null; 
    TopicSession session = null; 
    Topic topic = null; 

    public void setupPubSub() throws JMSException, NamingException { 

     Properties env = new Properties(); 
     env.setProperty("java.naming.factory.initial", 
       "org.jnp.interfaces.NamingContextFactory"); 
     env.setProperty("java.naming.factory.url.pkgs", 
       "org.jboss.naming:org.jnp.interfaces"); 
     env.setProperty("java.naming.provider.url", "jnp://localhost:1099"); 
     InitialContext iniCtx = new InitialContext(env); 
     Object tmp = iniCtx.lookup("ConnectionFactory"); 

     TopicConnectionFactory tcf = (TopicConnectionFactory) tmp; 
     conn = tcf.createTopicConnection("guest", "guest"); 
     conn.setClientID("Dirabla"); 
     topic = (Topic) iniCtx.lookup("topic/durableTopic"); 

     session = conn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); 
    } 

    public void recvSync() throws JMSException, NamingException { 
     System.out.println("Begin recvSync"); 
     setupPubSub(); 
     TopicPublisher topicPublisher = session.createPublisher(topic); 

     Message message = session.createMessage(); 

     for (int i = 0; i < 10; i++) { 
      message.setIntProperty("id", i); 
      topicPublisher.publish(message); 
     } 
    } 

    public void stop() throws JMSException { 
     conn.stop(); 
     session.close(); 
     conn.close(); 
    } 

    public static void main(String args[]) throws Exception { 
     System.out.println("Begin DurableTopicRecvClient, now=" 
       + System.currentTimeMillis()); 
     DurableTopicPublisher client = new DurableTopicPublisher(); 
     client.recvSync(); 
     client.stop(); 
     System.out.println("End DurableTopicRecvClient"); 
     System.exit(0); 
    } 

} 

トピック宣言はあなた

<?xml version="1.0" encoding="UTF-8"?> 
<server> 
    <mbean code="org.jboss.jms.server.destination.TopicService" name="jboss.messaging.destination:service=Topic,name=durableTopic" xmbean-dd="xmdesc/Topic-xmbean.xml"> 
    <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends> 
    <depends>jboss.messaging:service=PostOffice</depends> 
</mbean> 
</server> 

スクリーンショット012と同様です

enter image description here

+0

私はあなたのDurableMessageListenerとDurableTopicSubscriberをjbossに追加しましたが、私はまだ4つの非永続サブスクリプションと0つの永続サブスクリプション(私の以前のMDBであったものの2つ)しか見ることができません。多分、私のjbossに問題があり、それを後で調べようとします。 – r3mbol

+0

いいえ、jbossではありません。私は新しいjboss-5.1.0.GA-jdk6をダウンロードし、すべてのjarsとservice.xmlをコピーして展開し、_default_と_all_configsで実行し、非永続サブスクリプションを残しました。 – r3mbol

関連する問題