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
你不能像我說的那樣,經紀人儘可能快地傳遞信息。如果你再次收到同樣的信息,那麼你可能需要檢查你的製作人,看看他們是否複製了他們的發送等等。很難說給予最少的信息 –