无法从JMS侦听器获取域对象

时间:2010-08-17 07:03:43

标签: grails jms dns

在我的应用程序中,我正在尝试向某些“事件发生”的客户发送电子邮件,例如。比如当我们收到付款或新客户登录时......

我成功捕获到那些事件,我正在尝试发送邮件,这就是我使用JMS在后台发送所有这些邮件功能的问题。

因此,当新客户注册时,我将其详细信息保存在数据库中,并生成一个事件。现在发送邮件我需要使用下面的代码访问客户(或任何其他相关的域对象)的信息

protected Map getObjectsMap(Map domainMap){
    Map objectsMap = [:]
    domainMap.each{key,value->
        def dc = grailsApplication.domainClasses.find{it.getFullName().equals(key)}
       // println "dc=$dc; dump=${dc.dump()}" // org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass

        def obj = dc.clazz.get(value)
        //println "value=$value return=$obj; dc.clazz=$dc.clazz; dump=${dc.clazz.dump()}"
        if(!obj) {
            log.error "Could not find object of type $key with id=$value"
            //def session = sessionFactory.currentSession
            //println "session=$session; dump=${session?.dump()}"

        }
        String objectName = key.substring(key.lastIndexOf(".")+1)
        objectName = objectName.charAt(0).toLowerCase().toString() + objectName.substring(1)
        objectsMap.put(objectName, obj)
    }
    return objectsMap
}

问题是此代码在我的本地计算机上运行(速度较慢),但不在生产服务器上运行。

我认为正在发生的事情是这个背景事件比将对象保存到DB更早执行。 (当我保存实例时,我确实有.save(flush:true))。这是我得到的堆栈跟踪

biz.MailService Could not find object of type customer.Customer with id=5
biz.MailService Could not find object of type customer.Customer with id=5
biz.MailService Could not find object of type payment.Payment with id=7
biz.MailService Could not find object of type payment.Payment with id=7
Mail$$EnhancerByCGLIB$$25d09edf.send Exception raised in message listener
org.springframework.jms.listener.adapter.ListenerExecutionFailedException: Listener method 'send' threw exception; nested exception is java.lang.AssertionError: Could not find the org property. Dumping objectMap: [customer:null, payment:null]. Dumping domainMap: [com.blusynergy.blubilling.customer.Customer:5, com.blusynergy.blubilling.payment.Payment:7]. Expression: org. Values: org = null
    at org.springframework.jms.listener.adapter.MessageListenerAdapter.invokeListenerMethod(MessageListenerAdapter.java:471)
    at grails.plugin.jms.listener.adapter.LoggingListenerAdapter.super$2$invokeListenerMethod(LoggingListenerAdapter.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1049)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:923)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:127)
    at grails.plugin.jms.listener.adapter.PersistenceContextAwareListenerAdapter.invokeListenerMethod(PersistenceContextAwareListenerAdapter.groovy:29)
    at org.springframework.jms.listener.adapter.MessageListenerAdapter.onMessage(MessageListenerAdapter.java:355)
    at grails.plugin.jms.listener.adapter.LoggingListenerAdapter.super$2$onMessage(LoggingListenerAdapter.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1049)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:923)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:127)
    at grails.plugin.jms.listener.adapter.LoggingListenerAdapter.onMessage(LoggingListenerAdapter.groovy:33)
    at grails.plugin.jms.listener.adapter.PersistenceContextAwareListenerAdapter.super$3$onMessage(PersistenceContextAwareListenerAdapter.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1049)
    at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:923)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:127)
    at grails.plugin.jms.listener.adapter.PersistenceContextAwareListenerAdapter.onMessage(PersistenceContextAwareListenerAdapter.groovy:18)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:534)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:495)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:467)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:323)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:261)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:977)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:969)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:871)
    at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.AssertionError: Could not find the org property. Dumping objectMap: [customer:null, payment:null]. Dumping domainMap: [com.blusynergy.blubilling.customer.Customer:5, com.blusynergy.blubilling.payment.Payment:7]. Expression: org. Values: org = null
    at org.codehaus.groovy.runtime.InvokerHelper.assertFailed(InvokerHelper.java:379)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.assertFailed(ScriptBytecodeAdapter.java:662)
    at com.blusynergy.blubilling.biz.MailService.send(MailService.groovy:185)
    at com.blusynergy.blubilling.biz.MailService$$FastClassByCGLIB$$88e80e6a.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
    at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:692)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:625)
    at com.blusynergy.blubilling.biz.MailService$$EnhancerByCGLIB$$25d09edf.send(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273)
    at org.springframework.jms.listener.adapter.MessageListenerAdapter.invokeListenerMethod(MessageListenerAdapter.java:463)
    ... 43 more

关于如何解决这个问题的任何想法.. ??

关心。

1 个答案:

答案 0 :(得分:0)

您是在事务中创建对象吗?

如果是,请确保在事务完成后发送消息。

如果没有,可能会实施某种重试系统。

欢呼声