有两个程序:订阅者和发布者...订阅者能够将消息放入主题并且消息成功发送.当我在浏览器上检查activemq服务器时,它显示1 msg排队.但是当我运行消费者代码时,它没有收到消息
这是生产者代码:
import javax.jms.*;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
public class producer {
private static String url = ActiveMQConnection.DEFAULT_BROKER_URL;
public static void main(String[] args) throws JMSException {
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
Connection connection = connectionFactory.createConnection();
connection.start();
// JMS messages are sent and received using a Session. We will
// create here a non-transactional session object. If you want
// to use transactions you should set the first parameter to 'true'
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic("testt"); …
Run Code Online (Sandbox Code Playgroud) 我是Java的新手.我只编程了大约一年.Spring使用模板意味着什么?在Spring中,有jdbc-templates,jms-templates等..什么是java中的模板类?它们是一种特殊的设计模式还是什么?
先感谢您.
如何使用JMS进行单元测试?这是事实吗?
我google了一些东西 - JMS的单元测试:http ://activemq.apache.org/how-to-unit-test-jms-code.html - jmsTemplate:activemq.apache.org/jmstemplate-gotchas.html - mockRunner:mockrunner .sourceforge.net /
你对我有什么好的经验和建议吗?
我有一个简单的 Spring Boot 服务,它使用 JMSTemplate 侦听 AWS SQS 队列。当消息得到正确处理时,一切都按预期工作。
我正在使用 CLIENT_ACKNOWLEDGE,因此在处理过程中抛出异常时,会再次收到消息。但是,SQS 队列上的默认可见性超时设置将被忽略,并且会立即再次接收消息。
SQS 队列配置了 30 秒的默认可见性超时,并且在将消息放入 DLQ 之前接收的重新驱动策略为 20。
我已禁用该服务并使用 SQS 控制台来验证是否正确设置了默认可见性超时。我还尝试将 JMS 消息添加到方法签名并执行手动验证。
这是 JMS 配置的代码:
@Configuration
@EnableJms
class JmsConfig
{
@Bean
@Conditional(AWSEnvironmentCondition.class)
public SQSConnectionFactory connectionFactory(@Value("${AWS_REGION}") String awsRegion)
{
return new SQSConnectionFactory(
new ProviderConfiguration(),
AmazonSQSClientBuilder.standard()
.withRegion(Regions.fromName(awsRegion))
.withCredentials(new DefaultAWSCredentialsProviderChain())
);
}
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory)
{
DefaultJmsListenerContainerFactory factory =
new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setDestinationResolver(new DynamicDestinationResolver());
factory.setConcurrency("3-10");
factory.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
factory.setErrorHandler(defaultErrorHandler());
return factory;
}
@Bean
public ErrorHandler defaultErrorHandler()
{
return new ErrorHandler()
{ …
Run Code Online (Sandbox Code Playgroud) 作为我的问题标题,如何在春季为weblogic配置jms模板?
我在一些网站上举了一个例子,但是春天总是在JmsTemplate上抱怨defaultDestination
如何正确配置?
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
<prop key="java.naming.provider.url">t3://localhost:7001</prop>
</props>
</property>
</bean>
<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="jndiName" value="jms/confactory" />
</bean>
<bean id="jmsDestinationResolver" class="org.springframework.jms.support.destination.JndiDestinationResolver">
<property name="jndiTemplate" ref="jndiTemplate" />
<property name="cache" value="true" />
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destinationResolver" ref="jmsDestinationResolver" />
</bean>
Run Code Online (Sandbox Code Playgroud)
nb:我使用weblogic 9.2 for jms&web server,spring 2.5.6
我试图使用Spring JMSTemplate.receive(String)方法以同步模式从队列中获取所有消息.
问题是我总是只收到一条消息.这是代码:
@Transactional
public List<Message> receiveAllFromQueue(String destination) {
List<Message> messages = new ArrayList<Message>();
Message message;
while ((message = queueJmsTemplate.receive(destination)) != null) {
messages.add(message);
}
return messages;
}
Run Code Online (Sandbox Code Playgroud)
如果我删除了@Transactional注释,我会收到所有消息,但所有消息都是在事务中完成的,所以如果稍后在处理这些消息时会有一个例外,消息将会丢失.
这是我的JMSTemplate bean的定义.
<bean id="queueJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="pubSubDomain" value="false" />
<property name="receiveTimeout" value="1" />
<property name="sessionTransacted" value="true" />
</bean>
Run Code Online (Sandbox Code Playgroud)
我想要实现的是拥有一个事务,并且在此事务中我想获取所有待处理的消息.
我正在尝试将消息头插入 amq。JMSTemplate 中没有特定方法用于在 amq 中设置 header。当我这样设置时,它将保存在StringProperty而不是标题中。保存到标题如何传递数据
amqTemplate.convertAndSend(goMQ, message,new MessagePostProcessor() {
@Override
public Message postProcessMessage(Message message) throws JMSException {
message.setStringProperty("test1","testdata");
message.setStringProperty("country","US");
//setObjectProperty -- also set the string property
return message;
}
});
Run Code Online (Sandbox Code Playgroud)
我需要将数据发送到标题中,客户端将为我的消息标题实现选择器。
JMS 会话到底是什么意思?
JMS 会话可以或不可以“交易”是什么意思?
JMS 会话可以带有或不带有“自动确认”是什么意思?
我编写了一个在Glassfish的Web服务中运行的JMS应用程序(也在JBoss中部署),我注意到在通过MessageListener MDP处理多个消息后,JMS服务器用完了连接!
用Apache ActiveMQ和Glassfish内部JMS代理(openMQ?)试过它
有没有办法检查为什么会这样?如果这是JmsTemplate的默认行为,那么以正确的方式开发JMS生产者和消费者的替代方法是什么?
谢谢!
我希望能够从application.properties设置@JMSlistener目标
我的代码看起来像这样
@Service
public class ListenerService {
private Logger log = Logger.getLogger(ListenerService.class);
@Autowired
QueueProperties queueProperties;
public ListenerService(QueueProperties queueProperties) {
this.queueProperties = queueProperties;
}
@JmsListener(destination = queueProperties.getQueueName() )
public void listenQueue(String requestJSON) throws JMSException {
log.info("Received " + requestJSON);
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我建造时
Error:(25, 60) java: element value must be a constant expression
Run Code Online (Sandbox Code Playgroud) jmstemplate ×10
java ×5
jms ×5
spring ×5
spring-jms ×4
amazon-sqs ×1
amq ×1
camera ×1
jdbctemplate ×1
jms-topic ×1
mocking ×1
spring-boot ×1
transactions ×1
unit-testing ×1
weblogic ×1