简体   繁体   English

通用JMS客户端

[英]Generic JMS Client

Does anyone know if it is feasible to write a Generic JMS client - ie. 有谁知道编写通用JMS客户端是否可行 - 即。 one that works with JMS from different providers (eg. Sonic, IBM SIB, Jboss etc)? 与不同提供商的JMS合作的一个(例如Sonic,IBM SIB,Jboss等)?

Every time I've written JMS client code it is always very implementation specific with dependent JARs and Context classes. 每次我编写JMS客户端代码时,它总是非常特定于实现,具有依赖的JAR和Context类。

Thanks. 谢谢。

Well, one best practice (at least for me) is to use the non-arg InitialContext constructor and to put provider specific stuff (like the initial context factory and the provider url) in a jndi.properties file on the class path instead of hard coding these things. 好吧,一个最佳实践(至少对我而言)是使用非arg InitialContext构造函数并将提供者特定的东西(如初始上下文工厂和提供者url)放在类路径上的jndi.properties文件中而不是硬编码这些东西。 You'll also need to put the "right" JMS provider JARs on the class path. 您还需要将“正确的”JMS提供程序JAR放在类路径上。 In other words, you can have generic code but you still need to configure the runtime environment (unless you run your client code in a container like Spring). 换句话说,您可以拥有通用代码,但仍需要配置运行时环境(除非您在像Spring这样的容器中运行客户端代码)。

2 good answers already, but I'd like to add a bit of an explanation. 已经有2个好的答案,但我想补充一点解释。 JMS is an API standard, it does not define the wire protocol to the server. JMS是API标准,它没有为服务器定义有线协议。 Therefore all JMS implementations have different wire protocols - therefore you'll always need the vendor-specific JARs. 因此,所有JMS实现都有不同的有线协议 - 因此您始终需要特定于供应商的JAR。 It is impossible to create a JMS client library that is compatible with all JMS providers. 创建与所有JMS提供程序兼容的JMS客户端库是不可能的。
In your source code you should avoid vendor-specific features (eg TIBCO EMS lets you access destinations with non-JNDI, native names and it has custom acknowledge modes). 在源代码中,您应该避免特定于供应商的功能(例如,TIBCO EMS允许您使用非JNDI,本机名称访问目标,并且它具有自定义确认模式)。 If you always use JNDI lookups, then only the JNDI URL and the initial context factory name will be specific to the server type. 如果始终使用JNDI查找,则只有JNDI URL和初始上下文工厂名称将特定于服务器类型。

This is what Spring is for. 这就是Spring的用途。 You will have vendor specific implementation but the code should be the same. 您将具有特定于供应商的实现,但代码应该相同。 See 19.6 JMS and 21. JMS (Java Message Service) of the Spring 3.0 Reference . 请参见19.6 JMS21. Spring 3.0 Reference的 JMS(Java消息服务)

对于未来寻找通用客户端的任何人,请尝试为主要JMS提供程序(ActiveMQ,WebSphere MQ等)提供插件的HermesJMS

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM