0
我使用带默认ActiveMQ的JBoss向已订阅主题的某些客户端发送消息。不幸的是,onMessage(Message message)
被多次调用仅仅一条消息。JBoss ActiveMQ主题RedeliveryDelay太小
JNDI的查找:
private static void lookupRemoteTopic() throws NamingException, JMSException
{
final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
final String DEFAULT_DESTINATION = "jms/topic/refresh";
final String DEFAULT_USERNAME = "ejb";
final String DEFAULT_PASSWORD = "ejbSuperSecret";
final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
final String PROVIDER_URL = "http-remoting://192.168.2.72:8080";
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL, PROVIDER_URL);
env.put(Context.SECURITY_PRINCIPAL, DEFAULT_USERNAME);
env.put(Context.SECURITY_CREDENTIALS, DEFAULT_PASSWORD);
InitialContext namingContext = new InitialContext(env);
// Perform the JNDI lookups
TopicConnectionFactory connectionFactory = (TopicConnectionFactory) namingContext.lookup(DEFAULT_CONNECTION_FACTORY);
Topic destination = (Topic) namingContext.lookup(DEFAULT_DESTINATION);
TopicConnection con = connectionFactory.createTopicConnection(DEFAULT_USERNAME, DEFAULT_PASSWORD);
con.start();
TopicSession session = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber sub = session.createSubscriber(destination);
sub.setMessageListener(this);
}
的onMessage:
public void onMessage(Message message)
{
try
{
// Do some stuff with it
}
catch (JMSException e)
{
e.printStackTrace();
}
}
邮件发件人:一个消息已发送
@Inject
private JMSContext context;
@Resource(lookup = "java:/jms/topic/refresh")
private Destination topic;
MapMessage mesg = context.createMapMessage();
// set message body
context.createProducer().send(topic, mesg);
后,客户得到轰炸的消息,虽然AUTO_ACKNOWLEDGE
已设置。
我该如何减慢发件人速度?
如果需要的SSCCE,我可以提供一个,它仅仅是一个很多,包括(服务器,客户端,配置等)
我不介意速度,只是'onMessage'被多次调用,只有一条消息。那不是'AUTO_ACKNOWLEDGE'应该做什么,以便消息得到确认并可以从服务器中删除?我如何设定重新投递之间的延迟? – TheFreddy1404
你不能像我说的那样,经纪人尽可能快地传递信息。如果你再次收到同样的信息,那么你可能需要检查你的制作人,看看他们是否复制了他们的发送等等。很难说给予最少的信息 –