使用哪些Maven依赖关系可以为Glassfish创建独立的JMS客户端? [英] With which maven dependencies can i create a standalone JMS client for Glassfish?

查看:90
本文介绍了使用哪些Maven依赖关系可以为Glassfish创建独立的JMS客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的项目是使用maven构建的。



我知道似乎有一些关于JMS依赖关系的混乱,所以,我在我的pom中使用哪些依赖关系


  1. 连接到我的JNDI上下文

  2. 能够阅读我的JMS主题?

我的Java测试方法是

  / **感谢WELD CDI,此方法不是静态的* / 
public void main(@Observes ContainerInitialized event)throws Throwable {
Context context = new InitialContext();
ConnectionFactory factory =(ConnectionFactory)context.lookup(JMSNotifierConstants.CONNECTION_FACTORY_NAME);
连接连接= factory.createConnection();
主题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(收到);
}
}

现在,我的pom包含以下依赖关系

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


解决方案

好的,这个比较棘手。



经过一些搜索和尝试之后,我移除了焊接依赖关系(以便返回到更经典的main)。

然后,我用

 <$替换了我的(旧式) appserv-rt.jar 依赖项c $ c>< dependency> 
< groupId> org.glassfish.appclient< / groupId>
< artifactId> gf-client< / artifactId>
< version> 3.1< / version>
< type> pom< / type>
< scope>编译< / scope>
< /依赖关系>

这是 not 一点变化,如 gf-client 为Glassfish提供了所有的罐子,这显然使很多罐子(希望有一种方法来优化jar数量,尽管我们都知道过早优化)。



因此,一旦完成,完全可以使用EJB远程接口,但不是 JMS(由于不可理解的原因)。为了使JMS与gf-client一起工作,必须为 imqjmsra.jar imqbroker.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.xsdxmlns =http://maven.apache.org/POM/4.0.0
xmlns:xsi =http://www.w3。组织/ 2001 / XMLSchema的实例>
< modelVersion> 4.0.0< / modelVersion>
< groupId> org.glassfish.external.jms< / groupId>
< artifactId> imqjmsra< / artifactId>
< version> 3.1.0< / version>
< description> POM由Sonatype Nexus创建< / description>
<依赖关系>
< dependency>
< groupId> org.glassfish.external.jms< / groupId>
< artifactId> imqbroker< / artifactId>
< version> 3.1.0< / version>
< /依赖关系>
< /依赖关系>
< / project>

imqjmsra.jar相关


 <?xml version =1.0encoding =UTF-8?> 
< project xsi:schemaLocation =http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdxmlns = 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由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>编译< / scope>
< /依赖关系>
< dependency>
< groupId> org.glassfish.external.jms< / groupId>
< artifactId> imqjmsra< / artifactId>
< version> 3.1.0< / version>
< /依赖关系>

我可以完全轮询我的JMS队列。


i want to create a very simple JMS standalone client to a JMS Topic hosted on my Glassfish server.

My project is built using maven.

I know there seems to be some kind of mess concerning JMS dependencies to use, so, which dependencies shouls I use in my pom to

  1. Connect to my JNDI context
  2. Be able to read my JMS topic ?

My Java test method is

/** 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);
    }
}

And my pom contains, for now, the following dependencies

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

解决方案

OK, this one was rather tricky.

After some searches and tries, I removed weld dependencies (in order to go back to a more classical main).

Then, I replaced my (old-style) appserv-rt.jar dependency with

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

This is not a little change, as gf-client pulls all jars for Glassfish, which obviously makes a lot of jars (hopefully there is a method to optimize jar number, although we all know about premature optimization).

So, once it's done, it's perfectly possible to use EJB remote interface, but not JMS (due to incomprehensible reasons). In order to make JMS work with gf-client, one then have to go create maven dependencies for imqjmsra.jar and imqbroker.jar, both located in %GLASSFISH3_INSTALL_DIR%/glassfish/lib/install/applications/jmsra. Furthermore, as imqjmsra.jar internally uses imqbroker.jar, I recommend you to create the following 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>

associated to imqjmsra.jar and

<?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>

associated to imqbroker.jar.

Obviously, as I use Nexus repository management, it was easier for me to create these dependencies in our company 3rd parties local repository using Nexus "upload artifact page".

Once it's done, My POM dependencies now are

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

And I can totally poll my JMS queue.

这篇关于使用哪些Maven依赖关系可以为Glassfish创建独立的JMS客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆