繁体   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