ActiveMq - Kaha - 商店已锁定...等待 10 秒商店解锁

发布于 2024-12-13 13:09:45 字数 1750 浏览 0 评论 0原文

我的应用程序有两个队列(Spring3-Hibernate-ActiveMq)。感谢您提前发表评论。如果您帮助我避免以下错误,我将很高兴:

10:02:41,541 INFO KahaStore:463 - Kaha Store using data directory \tmp\kahadb 10:02:41,542 信息 KahaPersistenceAdapter:185 - 商店已锁定...等待 10 秒以解锁商店。 10:02:51,542 信息 KahaStore:463 - 使用数据目录 \tmp\kahadb 的 Kaha 存储 10:02:51,543 信息 KahaPersistenceAdapter:185 - 商店已锁定...等待 10 秒以解锁商店。 10:03:01,543 信息 KahaStore:463 - 使用数据目录 \tmp\kahadb 的 Kaha 存储 .. 。

这是我的 applicationContext.xml

<amq:connectionFactory id="amqConnectionFactory"
    brokerURL="vm://localhost" />

<bean id="connectionFactory"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <constructor-arg ref="amqConnectionFactory" />  
    <property name="sessionCacheSize" value="100" />
</bean>

<bean id="jmsTemplateForProduct" class="org.springframework.jms.core.JmsTemplate"
    p:defaultDestinationName="Click.Queue.Product">
    <constructor-arg ref="connectionFactory" /> 
</bean>

<bean id="jmsTemplateForPayment" class="org.springframework.jms.core.JmsTemplate"
    p:defaultDestinationName="Click.Queue.Payment">
    <constructor-arg ref="connectionFactory" /> 
</bean>

<jms:listener-container concurrency="10">
    <jms:listener id="ProductListener" destination="Click.Queue.Product"
        ref="productListener" />
</jms:listener-container>

<jms:listener-container concurrency="10">
    <jms:listener id="PaymentListener" destination="Click.Queue.Payment"
        ref="paymentListener" />
</jms:listener-container>
<!-- ActiveMQ ends -->

I have two queues on my application (Spring3-Hibernate-ActiveMq). Thanks for your comments in advance. I would be glad if you help me avoid the following error:

10:02:41,541 INFO KahaStore:463 - Kaha Store using data directory \tmp\kahadb
10:02:41,542 INFO KahaPersistenceAdapter:185 - Store is locked... waiting 10 seconds for the Store to be unlocked.
10:02:51,542 INFO KahaStore:463 - Kaha Store using data directory \tmp\kahadb
10:02:51,543 INFO KahaPersistenceAdapter:185 - Store is locked... waiting 10 seconds for the Store to be unlocked.
10:03:01,543 INFO KahaStore:463 - Kaha Store using data directory \tmp\kahadb
..
.

And Here is my applicationContext.xml

<amq:connectionFactory id="amqConnectionFactory"
    brokerURL="vm://localhost" />

<bean id="connectionFactory"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <constructor-arg ref="amqConnectionFactory" />  
    <property name="sessionCacheSize" value="100" />
</bean>

<bean id="jmsTemplateForProduct" class="org.springframework.jms.core.JmsTemplate"
    p:defaultDestinationName="Click.Queue.Product">
    <constructor-arg ref="connectionFactory" /> 
</bean>

<bean id="jmsTemplateForPayment" class="org.springframework.jms.core.JmsTemplate"
    p:defaultDestinationName="Click.Queue.Payment">
    <constructor-arg ref="connectionFactory" /> 
</bean>

<jms:listener-container concurrency="10">
    <jms:listener id="ProductListener" destination="Click.Queue.Product"
        ref="productListener" />
</jms:listener-container>

<jms:listener-container concurrency="10">
    <jms:listener id="PaymentListener" destination="Click.Queue.Payment"
        ref="paymentListener" />
</jms:listener-container>
<!-- ActiveMQ ends -->

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花想c 2024-12-20 13:09:45

嗯,我自己解决了这个问题。顺便说一句,感谢 jkysam 的评论。

该问题是由于多次加载applicationContext而发生的。因此,每当加载 applicationContext 时,都会创建 kaha db 的新实例并导致锁定。

我所做的是将jms相关配置从applicationContext中分离出来。因此,我创建了一个名为 jmsContext.xml 的新上下文 xml 文件,并将 jms(以及 activemq)相关配置行移至该文件。然后在我的测试类中,我加载了不同的上下文 xml,具体取决于它是否是 jmsTest。

例如;我有两个 GenericUnitTest 类来分隔上下文配置。第一个是:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/jmsContext.xml"})
public abstract class GenericJmsUnitTest {  
}   

第二个是:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/applicationContext.xml"})
public abstract class GenericUnitTest { 
}   

然后我根据测试用例扩展这些类。这是例子;

public class ProductQueueTest extends GenericJmsUnitTest{  
@Autowired
private ProductQueueService productQueueService;

@Test
    public void productTest() {   
     productQueueService.sendProduct(); 
    }
}

非jms测试类示例是:

public class SchedularTest extends GenericUnitTest {
    @Autowired
    private Processor schedulerProcessor;

    @Test
     public void scheduleForProduct() {
        schedulerProcessor.processForProducts();
    }
}

顺便说一句,我在applicationContext.xml中排除了与队列有关的组件扫描过滤器,并将它们包含在jmsContext.xml中。这是例子;

applicationContext xml如下


  <上下文:排除过滤器类型=“正则表达式”表达式=“com.project.queue.*”/>
  <上下文:排除过滤器类型=“正则表达式”表达式=“com.project.test.queue.*”/>

jmsContext xml如下

 >
 >

Well, I have solved the problem by myself. BTW thanks jkysam for your comments.

The problem was occured because of loading of applicationContext more than once. So, anytime applicationContext is loaded, a new instance of kaha db is created and it results to locking.

What I did is that I seperated jms related configuration from applicationContext. So, I created a new context xml file called jmsContext.xml, and move the jms (and activemq as well) related configuration lines to that file. Then in my test classes, I loaded different context xml's depend on whether it is a jmsTest or not.

For instance; I have two GenericUnitTest class in order to seperate context configuration. First is:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/jmsContext.xml"})
public abstract class GenericJmsUnitTest {  
}   

Second one is:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/applicationContext.xml"})
public abstract class GenericUnitTest { 
}   

And then I extend these classes depend on the test case. Here is the example;

public class ProductQueueTest extends GenericJmsUnitTest{  
@Autowired
private ProductQueueService productQueueService;

@Test
    public void productTest() {   
     productQueueService.sendProduct(); 
    }
}

The non-jms test class sample is:

public class SchedularTest extends GenericUnitTest {
    @Autowired
    private Processor schedulerProcessor;

    @Test
     public void scheduleForProduct() {
        schedulerProcessor.processForProducts();
    }
}

BTW, I exclude component scan filters which are about queue in applicationContext.xml, And include them in jmsContext.xml. Here is the example;

applicationContext xml is below

<context:component-scan base-package="com.project">
  <context:exclude-filter type="regex" expression="com.project.queue.*"/>
  <context:exclude-filter type="regex" expression="com.project.test.queue.*"/>
</context:component-scan>

jmsContext xml is below

 <context:component-scan base-package="com.project.queue"/>
 <context:component-scan base-package="com.project.test.queue"/>
心房敞 2024-12-20 13:09:45

Kaha 是 ActiveMQ 的持久性存储,它有一个锁定文件,可防止多个 AMQ 进程访问它同时。在干净退出时,此锁将始终被删除,但如果由于任何原因该过程未正确完成,则可能不会删除该锁。此外,如果您运行多个代理,它们可能会默认为相同的 Kaha 位置(在您的情况下为 \tmp\kahadb),并且其中之一将无法到达商店。有关重新配置位置的方法,请参阅 Kaha 链接。

如果这些场景都不适合您的情况,您可能会遇到代理的合法问题,但您需要提供有关如何使锁定检查代码失败的更多详细信息。

Kaha is ActiveMQ's persistency store and it has a lock file that prevents multiple AMQ processes from accessing it at the same time. On a clean exit this lock will always be removed but if for any reason the process didn't finish correctly the lock might not be deleted. Also, if you are running multiple brokers they could be defaulting to the same Kaha location, in your case \tmp\kahadb, and one of them wouldn't get to the store. See the Kaha link for a way to reconfigure the location.

If neither one of those scenarios applies to your situation you might have run into a legitimate problem with broker but you need to provide more details about how you get the lock checking code to fail.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文