我和我的开发人员遇到了一个问题,当我们不想要它们时,我们的应用程序中的对象被垃圾收集.我们在Weblogic 10g3中使用Java.我们正在编写单例模式来处理所有JMS连接.
涉及两个类:
public class JMSObject {
...
private MessageProducer _producer;
private MessageConsumer _consumer;
...
// standard get/set procs... etc.
}
public class JMSFactory {
...
// Hashmap sessions with key == ConnectionFactory Name
Hashmap<String, List<Session>> _sessions;
// Hashmap of JMSObjects with key == ConnectionFactory Name + JMS Queue Name
Hashmap<String, List<JMSObject>> _jmsobjects;
...
// standard get/set & necessary sington functions
}
Run Code Online (Sandbox Code Playgroud)
Servlet的init方法调用JMSFactory单元方法,任何新的Sessions都放在_sessions Hashmap中,新的MessageConsumer/MessageProducers作为JMSObject创建,并放在_jmsobjects Hashmap中的相应List中.
问题是,当系统运行时,列表中的JMSObjects会在一段时间后收集垃圾(有时在几小时后的其他时间会收集5分钟.)我们查看了几天,但找不到任何JMSObjects的原因被收集的野蛮人.既然JMSFactory引用了它们,为什么gc会破坏它们呢?
最后,我们通过更改类来修复它(不更改方法接口):
public class JMSObject {
...
private List<MessageProducer> _producers;
private List<MessageConsumer> _consumers;
...
// …Run Code Online (Sandbox Code Playgroud) 我想要在独立应用程序中传递这些行中的最后一行而不抛出任何异常:
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"weblogic.jndi.WLInitialContextFactory");
props.setProperty("java.naming.provider.url",
"t3s://localhost:9002");
props.setProperty("java.naming.security.principal",
"<username>");
props.setProperty("java.naming.security.credentials",
"<password>");
Context ctx = new InitialContext(props);
Run Code Online (Sandbox Code Playgroud)
...但我在异常中获得此信息:
Warning Security BEA-090542 Certificate chain received from localhost - 127.0.0.1 was not trusted causing SSL handshake failure. Check the certificate chain to determine if it should be trusted or not. If it should be trusted, then update the client trusted CA configuration to trust the CA certificate that signed the peer certificate chain. If you are connecting to a WLS …
如果通过指定sessionTransacted=true或启用DefaultMessageListenerContainer上的事务管理transactionManager=jmsTransactionManager,则只要MDP中发生异常,事务就会回滚并将消息放回到队列中。然后,该消息将再次被处理,事务又一次又一次地回滚,从而创建了一个无限循环。
我想我的问题是……我在这里想念什么?如果只是意味着将一遍又一遍地处理消息,为什么还要让消息返回队列呢?
<!-- jms connection factory -->
<bean name="jmsConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:ConnectionFactory" />
</bean>
<!-- jms transaction manager -->
<bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
<!-- Destination for Inbound_Email_Q -->
<bean name="inboundEmailDestination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="queue/inbound_Email_Queue" />
</bean>
<!-- JmsTemplate for Inbound_Email_Q -->
<bean name="jmsInboundEmailTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="jmsConnectionFactory" />
<property name="defaultDestination" ref="inboundEmailDestination" />
<property name="messageConverter" ref="xmlMessageConverter" />
</bean>
<!-- jms asynchronous listener -->
<bean id="emailMessageServiceMdp" class="org.site.wso.core.jms.EmailMessageServiceMdp" />
<bean class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsConnectionFactory"/> …Run Code Online (Sandbox Code Playgroud) 我试图让一个简单的JMS"Hello world"应用程序运行.我想在JBoss Application Server 7上试一试,但我无法运行它.作为HornetQ的Jboss嵌入其中,我使用以下命令启动它:
standalone.bat --server-config=standalone-preview.xml
Run Code Online (Sandbox Code Playgroud)
我认为问题很可能是我在JBoss中配置队列的方式.这是我做的步骤.
Quene名称:testQueue JNDI名称:queue/test
队列配置有一个"选择器"选项.这可以留空,如果没有,这个领域会发生什么?
这是我用作发件人的代码.我现在不担心接收器,因为我只想先开始发送消息.
package jms.ex3;
import javax.naming.InitialContext;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.QueueSender;
import javax.jms.DeliveryMode;
import javax.jms.QueueSession;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
public class Sender
{
public static void main(String[] args) throws Exception
{
// get the initial context
InitialContext ctx = new InitialContext();
// lookup the queue object
Queue queue = (Queue) ctx.lookup("queue/test");
// lookup the queue connection factory
QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.
lookup("queue/connectionFactory");
// create …Run Code Online (Sandbox Code Playgroud) 我的应用程序将消息写入JMS队列.我检查了调试器是否正确写入了所有内容.
在服务器控制台上,在JMS Monitoring中,我可以看到Message Current数量的增加(来自我的消息).
但是,有一个组件应该从队列中读取消息并在服务器计算机上写入文件,而这种情况并没有发生.我还不熟悉JMS.
我该怎么做才能解决这个问题?在我知道不是第三方,而是使用我们自己的应用程序之前,我应该在配置中寻找什么?
ActiveMQ 5.5.1
<c:route>
<c:from uri="jetty:http://0.0.0.0:8055/ws/despacho" />
<c:to uri="bean:despachoHandler" />
<c:to uri="activemq:queue:copom.out.test" pattern="InOut" />
</c:route>
Run Code Online (Sandbox Code Playgroud)
消息显示排队,但我无法使用它.一段时间后,我得到超时,消息转到ActiveMQ.DLQ.
org.apache.camel.ExchangeTimedOutException:未收到OUT消息:20000毫秒到期回复消息,其中relatedID:Camel-ID-SSP-SGPF-GITSAD-58215-1359134232568-0-3未收到.
如果我将其更改为pattern ="InOnly",我可以正常使用该消息.
这是怎么回事?
我有代理监听消息代理上的JMS队列.当我将消息发送到队列时,我将自定义属性设置为JMS消息.但是当我记录代理收到的消息时,没有自定义的JMS属性.
我如何在代理中获得自定义JMS属性?
我将WSO2 ESB 4.6.0与ActiveMQ 5.8.0一起使用.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="MyProxy" transports="https,TTP,http,jms" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="OUT_ONLY" value="true"/>
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
<log level="full"/>
</inSequence>
<outSequence>
<drop/>
</outSequence>
<endpoint>
<address uri="jms:/MyQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue" format="pox"/>
</endpoint>
</target>
</proxy>
Run Code Online (Sandbox Code Playgroud) 我们目前将JMS API与ActiveMQ代理一起使用,希望移至RabbitMQ。与openWire和amqp相比,使用java client-producer可以获得最佳性能。我找不到关于amqp(RabbitMQ)与openwire(activeMQ)本机协议的比较研究。我正在寻找原始性能和易于扩展性。
当前,我们将Spring Integration用于ActiveMQ,我想知道即使使用Spring Integration,将其迁移到RabbitMQ(AMQP)是否进行了重大更改。是否有与ActiveMQ用于执行JMS <-> AMQP转发的桥相似的桥?
我需要为IBM MQ编写简单的Java客户端.使用WebSphere MQ classes for Java(com.ibm.mq.jar)而不是使用WebSphere MQ classes for JMS(jms.jar)在Java中编写MQ客户端有什么好处?
我将配置两个Wildfly-Swarm(Version 2018.5.0)服务器远程服务器。第一台服务器应将消息(通过wildfly-swarm消息传递)发送到第二台服务器。在第二台服务器上,正在运行用于消息传递的使用者。
在阅读了很多(过时的)教程之后,我得出的结论是我很愚蠢。
我在一个服务器上构建了一个包含Wildfly-Swarm消息传递的测试项目。
project-default.yaml
swarm:
messaging-activemq:
servers:
default:
jms-queues:
my-queue: {}
jms-topics:
my-topic: {}
logging:
pattern-formatters:
LOG_FORMATTER:
pattern: "%p [%c] %s%e%n"
periodic-rotating-file-handlers:
FILE:
file:
path: pathtolog/swarm.log
suffix: .yyyy-MM-dd
named-formatter: LOG_FORMATTER
level: ALL
root-logger:
handlers:
- FILE
Run Code Online (Sandbox Code Playgroud)
MyApplication.java
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/")
public class MyApplication extends Application
{
}
Run Code Online (Sandbox Code Playgroud)
MyResource.java
import javax.annotation.Resource;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.jms.JMSContext;
import javax.jms.Topic;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.util.logging.Level;
import java.util.logging.Logger;
@ApplicationScoped
@Path("/")
public class MyResource
{
Logger LOG = …Run Code Online (Sandbox Code Playgroud)