---
title: "GRAILS JMS (sonicMQ）集成"
author: "seanwon"
date: "2009-02-02T17:27:00Z"
tags: []
categories: ["企业架构"]
slug: "grails-jms-sonicmq"
draft: false
lastmod: "2009-02-02T17:27:00Z"
id: 322022
url: "https://seanwon.iteye.com/blog/322022"
---

网上很多示例都是以activeMQ和openMQ为主，对SonicMQ的配置不多。

下面是针对sonicMQ的配置信息，resources.groovy内容如下：
*<span style="color:blue">beans = {

    connectionFactory(org.springframework.jndi.JndiObjectFactoryBean){
        jndiTemplate = ref("jndiTemplate")
        jndiName = "testConnectionFactory"
    }
    jndiTemplate(org.springframework.jndi.JndiTemplate){
        environment =
            
        
    }
}</span>*

这里jndiName对应的connectionFactory是在sonicMQ Management Cosole配置的，名字是testConnectionFactory。

接收的程序代码如下：

*<span style="color:blue">class SampleQ1Service {

    static expose = 
    static destination = "testQueue"
    def onMessage(messageObject) {
       println "GOT MESSAGE: $messageObject"
    }
}
</span>*
监听的Queue的名字是testQueue。
发送的代码如下：
*<span style="color:blue">class TestController {

    def index = {

        sendJMSMessage("testQueue", "Blog Entry entitled sss has been created.")

    }
}
</span>*

搞定了。