簡體   English   中英

使用哪個maven依賴項可以為Glassfish創建一個獨立的JMS客戶端?

[英]With which maven dependencies can i create a standalone JMS client for Glassfish?

我想為我的Glassfish服務器上托管的JMS主題創建一個非常簡單的JMS獨立客戶端。

我的項目是使用maven構建的。

我知道在使用JMS依賴關系時似乎有些混亂,因此,我在pom中使用了哪些依賴關系

  1. 連接到我的JNDI上下文
  2. 能夠閱讀我的JMS主題嗎?

我的Java測試方法是

/** Thanks to WELD CDI, this method is not static */
public void main(@Observes ContainerInitialized event) throws Throwable {
    Context context = new InitialContext();
    ConnectionFactory factory = (ConnectionFactory) context.lookup(JMSNotifierConstants.CONNECTION_FACTORY_NAME);
    Connection connection = factory.createConnection();
    Topic topic = (Topic) context.lookup(JMSNotifierConstants.NOTIFICATION_TOPIC);
    Session session = connection.createSession(false,
            Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(topic);
    connection.start();
    while (true) {
        Message received = consumer.receive();
        System.out.println(received);
    }
}

而我的pom目前包含以下依賴項

    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>1.0-SP1</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.weld</groupId>
        <artifactId>weld-se</artifactId>
        <version>1.0.1-Final</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.weld</groupId>
        <artifactId>weld-logger</artifactId>
        <version>1.0.0-CR2</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.1</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jdk14</artifactId>
        <version>1.6.1</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.jms</artifactId>
        <version>3.0</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.extras</groupId>
        <artifactId>appserv-rt</artifactId>
        <version>3.1</version>
    </dependency>

好的,這個很棘手。

經過一些搜索和嘗試后,我刪除了焊接依賴項(為了回到更經典的主要)。

然后,我用我的(舊式) appserv-rt.jar替換了

    <dependency>
        <groupId>org.glassfish.appclient</groupId>
        <artifactId>gf-client</artifactId>
        <version>3.1</version>
        <type>pom</type>
        <scope>compile</scope>
    </dependency>

這並沒有什么變化,因為gf-client為Glassfish提供了所有罐子,這顯然會產生很多罐子(希望有一種優化罐子數量的方法 ,盡管我們都知道過早優化)。

因此,一旦完成,完全可以使用EJB遠程接口,但不能使用 JMS(由於難以理解的原因)。 為了使JMS與gf-client一起工作,必須為imqjmsra.jarimqbroker.jar創建maven依賴imqjmsra.jar ,兩者都位於%GLASSFISH3_INSTALL_DIR%/glassfish/lib/install/applications/jmsra 此外,由於imqjmsra.jar內部使用imqbroker.jar ,我建議您創建以下poms:

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.glassfish.external.jms</groupId>
  <artifactId>imqjmsra</artifactId>
  <version>3.1.0</version>
  <description>POM was created by Sonatype Nexus</description>
  <dependencies>
    <dependency>
          <groupId>org.glassfish.external.jms</groupId>
          <artifactId>imqbroker</artifactId>
          <version>3.1.0</version>
    </dependency>
  </dependencies>
</project>

imqjmsra.jar和。相關聯

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.glassfish.external.jms</groupId>
  <artifactId>imqbroker</artifactId>
  <version>3.1.0</version>
  <description>POM was created by Sonatype Nexus</description>
</project>

imqbroker.jar相關聯。

顯然,當我使用Nexus存儲庫管理時,我更容易使用Nexus“上傳工件頁面”在我們公司的第三方本地存儲庫中創建這些依賴項。

一旦完成,我的POM依賴現在就是

    <dependency>
        <groupId>org.glassfish.appclient</groupId>
        <artifactId>gf-client</artifactId>
        <version>3.1</version>
        <type>pom</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.external.jms</groupId>
        <artifactId>imqjmsra</artifactId>
        <version>3.1.0</version>
    </dependency>

我可以完全輪詢我的JMS隊列。

對我來說有用的是從glassfish安裝文件夾添加gf-client.jar,但是從maven存儲庫添加gf-client不起作用。

使用maven依賴項時,我發現這有效: https//stackoverflow.com/a/10123034/516188

<dependency>
    <groupId>org.glassfish.main.extras</groupId>
    <artifactId>glassfish-embedded-all</artifactId>
    <version>3.1.2</version>
</dependency>

它生成了一個62Mb的最終JAR文件,但它確實有效。 接下來我遇到了這個問題,使用System.exit(0)作為那個問題: 發送帶有JMS的消息在退出時掛起

我正在從GF 2.1轉換到3.1並且我還沒有使用客戶端軟件(它肯定在我的列表中)但據我所知,你需要大部分使用GF 3.1安裝glassfish來使客戶端訪問發射。 (使用GF 2.1,它包含15個以上的mb文件)

“gf-client.jar引用GlassFish安裝目錄中的許多其他.jars,因此最好從安裝目錄本身引用它,而不是將它(以及所有其他.jars)復制到另一個位置” EJB FAQ

您可以使用自動生成的Webstart啟動與Application Client Container,也可以打包客戶端並手動部署它。 Glassfish 3.0手冊,ACC

您可以通過添加以下內容獲得imqbroker:

    <dependency>
        <groupId>com.sun.messaging.mq</groupId>
        <artifactId>imqbroker</artifactId>
        <version>4.5.1-b03</version>
    </dependency>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM