我可以使用哪些 Maven 依赖项为 Glassfish 创建独立的 JMS 客户端?
我想为我的 Glassfish 服务器上托管的 JMS 主题创建一个非常简单的 JMS 独立客户端。
我的项目是使用maven构建的。
我知道要使用的 JMS 依赖项似乎有些混乱,因此,我应该在 pom 中使用哪些依赖项来
- 连接到我的 JNDI 上下文
- 能够阅读我的 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>
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
- Connect to my JNDI context
- 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,这个相当棘手。
经过一些搜索和尝试后,我删除了焊接依赖项(以便回到更经典的主干)。
然后,我将我的(旧式)
appserv-rt.jar
依赖项替换为This is not a Little Change,因为
gf-client
拉动了所有 Glassfish 的罐子,这显然会产生很多罐子(希望有 一种优化 jar 数量的方法,尽管我们都知道过早优化)。因此,一旦完成,完全可以使用 EJB 远程接口,但不能 JMS(由于无法理解的原因)。为了使 JMS 与 gf-client 一起工作,必须为
imqjmsra.jar
和imqbroker.jar
创建 Maven 依赖项,它们都位于%GLASSFISH3_INSTALL_DIR 中%/glassfish/lib/install/applications/jmsra
。 以下 poms:此外,由于
imqjmsra.jar
内部使用imqbroker.jar
,我建议您创建与imqjmsra.jar
关联的并
关联到
imqbroker.jar
。显然,当我使用 Nexus 存储库管理时,我可以更轻松地使用 Nexus“上传工件页面”在我们公司的第 3 方本地存储库中创建这些依赖项。
完成后,我的 POM 依赖项现在是
我可以完全轮询我的 JMS 队列。
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 withThis 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
andimqbroker.jar
, both located in%GLASSFISH3_INSTALL_DIR%/glassfish/lib/install/applications/jmsra
. Furthermore, asimqjmsra.jar
internally usesimqbroker.jar
, I recommend you to create the following poms :associated to
imqjmsra.jar
and
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
And I can totally poll my JMS queue.
我正在从 GF 2.1 转换到 3.1,我还没有使用客户端软件(它肯定在我的列表中),但据我所知,您需要使用 GF 3.1 安装大部分 glassfish 才能让客户端发射。 (对于 GF 2.1,它是 15+ mb 的包含文件)
“gf-client.jar 引用了 GlassFish 安装目录中的许多其他 .jar,因此最好从安装目录本身引用它,而不是复制它(以及所有其他 .jar) 到另一个位置” EJB 常见问题解答
您可以使用应用程序客户端容器自动生成的 Webstart 启动,也可以打包客户端并手动部署它。 Glassfish 3.0 手册、ACC
I'm converting from GF 2.1 to 3.1 and I haven't got to the client software yet (it is definitely on my list) but as far as I can tell you need most of the glassfish install with GF 3.1 to get the client to launch. (With GF 2.1 it was 15+ mb include files)
"gf-client.jar refers to many other .jars from the GlassFish installation directory so it is best to refer to it from within the installation directory itself rather than copying it(and all the other .jars) to another location" EJB FAQ
You can either use the auto-generated webstart launch with Application Client Container, or you can package up your client and deploy it manually. Glassfish 3.0 manual, ACC
对我来说,有效的是从 glassfish 安装文件夹添加 gf-client.jar,但从 Maven 存储库添加 gf-client 不起作用。
当使用maven依赖项时,我发现这有效:
https://stackoverflow.com/a/10123034/516188
它生成了 62Mb 的最终 JAR 文件,但它可以工作。接下来我遇到了这个问题,使用 System.exit(0) 来解决这个问题:
使用 JMS 发送消息在退出时挂起
Well for me what worked was adding gf-client.jar from the glassfish installation folder, but adding gf-client from the maven repositories did not work.
When using maven dependencies, I found that this worked:
https://stackoverflow.com/a/10123034/516188
It makes for a 62Mb final JAR file, but it works. Next thing I hit this problem though, used System.exit(0) for that one:
Sending message with JMS hangs on exit
您可以通过添加以下内容来获取 imqbroker:
You can get imqbroker by adding this: