[英]Set maximum consumer count jms solace
我正在嘗試使用solace作為代理使用jms設置主題終結點的最大使用者數,因此,為了增加負載,可以在cloudfoundry中啟動該應用程序的多個實例,並且多個訂閱者可以使用同一主題的消息。
我嘗試了以下設置的多種組合( setConcurrency(), setConcurrentConsumers(), setMaxConcurrentConsumers()
,(20為任意高數字)。從文檔中判斷,我絕對需要使用setMaxConcurrentConsumers()
並將其設置為適當的值。高價值。
部署應用程序時,將創建主題端點,但是當我查看solace管理界面時,最大使用者數始終為1(如此處所示: Queues -> Topic Endpoints -> select endpoint -> Configured Limit
) ,即使應該為20。因此第二個使用者無法連接。 我不想每次部署應用程序時手動設置此設置。
import javax.jms.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
@Configuration
public class ProducerConfiguration {
private static final Log logger = LogFactory.getLog(SolaceController.class);
@Value("${durable_subscription}")
private String subscriptionName;
@Value("${topic_name}")
private String topic_name;
@Autowired
private ConnectionFactory connectionFactory;
@Bean
public JmsTemplate jmsTemplate() {
CachingConnectionFactory ccf = new CachingConnectionFactory(connectionFactory);
JmsTemplate jmst = new JmsTemplate(ccf);
jmst.setPubSubDomain(true);
return jmst;
}
@Bean
public Session configureSession(ConnectionFactory connectionFactory) throws JMSException {
return connectionFactory.createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
}
private TextMessage lastReceivedMessage;
public class SimpleMessageListener implements MessageListener {
@Override
public void onMessage(Message message) {
if (message instanceof TextMessage) {
lastReceivedMessage = (TextMessage) message;
try {
logger.info("Received message : " + lastReceivedMessage.getText());
} catch (JMSException e) {
logger.error("Error getting text of the received TextMessage: " + e);
}
} else {
logger.error("Received message that was not a TextMessage: " + message);
}
}
}
@Bean
public DefaultMessageListenerContainer orderMessageListenerContainer() {
DefaultMessageListenerContainer lc = new DefaultMessageListenerContainer();
lc.setConnectionFactory(connectionFactory);
lc.setDestinationName(topic_name);
lc.setMessageListener(new SimpleMessageListener());
lc.setDurableSubscriptionName(subscriptionName);
lc.setPubSubDomain(true);
//tried multiple combinations here, also setting only setMaxConcurrentConsumers
lc.setConcurrency("2-20");
lc.setConcurrentConsumers(20);
lc.setMaxConcurrentConsumers(20);
lc.setSubscriptionDurable(true);
lc.initialize();
lc.start();
return lc;
}
}
我認為在您的用例中,您的消費者陷入了困境。 參見https://solace.com/blog/topic-subscription-queues/
“ ...雖然多個使用者可以綁定到隊列,但是耐用的終結點僅限於單個主題訂閱。隊列允許多個主題訂閱以及主題通配符。”
如果您不想更改發布者,則可以嘗試“隊列上的主題訂閱”。 也就是說,可以將隊列配置為偵聽主題。 然后,您的消費者將從該隊列中獲取消息。
您需要創建一個非獨占的隊列/端點。
默認情況下,您創建的隊列是互斥隊列/端點,這意味着任何時間都只能綁定一個訂閱者。
創建此類隊列/端點的最簡單方法是通過Solace CLI。
要在JMS程序中創建非獨占隊列,您必須進入Solace特定的JMS實現,如下所示:
if (queueName != null) {
EndpointProperties props = new EndpointProperties();
props.setAccessType(EndpointProperties.ACCESSTYPE_NONEXCLUSIVE);
try {
((SolConnection)connection).getProperties().getJCSMPSession()
.provision(JCSMPFactory.onlyInstance().createQueue(queueName), props, 0L);
} catch (Exception e) {
e.printStackTrace();
}
queue = session.createQueue(queueName);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.