2012-02-24 86 views
1

是否有人配置了Grails 2.x JMS插件來發送/接收消息到遠程WebLogic JMS服務器?我已經試過resources.groovy配置這樣沒有運氣:Grails JMS插件到WebLogic JMS服務器

jmsConnectionFactory(InitialContext, [ 
"INITIAL_CONTEXT_FACTORY": "weblogic.jndi.WLInitialContextFactory", 
"PROVIDER_URL": "t3://remote-host:7001", 
"SECURITY_PRINCIPAL": "weblogic", 
"SECURITY_CREDENTIALS": "weblogic"]) 
+0

你能否提供一些額外的細節?在啓動或運行時失敗,堆棧跟蹤等? – proflux 2012-02-24 21:08:25

+0

我給出的配置是離開基地的,我從JMS插件得到一個關於無法找到jmsConnectionFactory的錯誤。我正在尋找任何有Grails連接到WebLogic JMS的例子。 – 2012-02-25 21:50:27

+0

如果你可以幫助[this](http://stackoverflow.com/questions/9436137/jms-job-queue-with-grails) – 2012-02-26 08:19:38

回答

0

沒有太多資源,完整的答案都在網上有關發送/與遠程Weblogic服務的Grails接收JMS,所以我想通了2 - 3年前一個工作解決方案,無需任何插件

  1. 確保至少Weblogic wlthint3client.jar是lib目錄。在服務/ myListenerService.groovy

    // Weblogic's JMS setup on Grails 
    jndiTemplate(org.springframework.jndi.JndiTemplate) { 
        environment = [ 
          "java.naming.factory.initial"  : "weblogic.jndi.WLInitialContextFactory", 
          "java.naming.provider.url"  : "t3://host.name.mustbe.same.as.configured.on.server.side:port_number", 
          "java.naming.security.principal" : "wlsadmin", 
          "java.naming.security.credentials": "password" 
        ] 
    } 
    
    
    // 
    // listener 
    // 
    jmsListenerConnectionFactory(org.springframework.jndi.JndiObjectFactoryBean) { 
        jndiTemplate = ref(jndiTemplate) 
        jndiName  = "jms.checkonserver.QueueConnectionFactory" 
    } 
    
    jmsListenerDestinationResolver(org.springframework.jms.support.destination.JndiDestinationResolver) { 
        jndiTemplate = ref(jndiTemplate) 
        cache = false 
    } 
    
    userListenerCredentialsConnectionFactory(org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter){ 
        targetConnectionFactory = ref(jmsListenerConnectionFactory) 
    } 
    
    standardListenerJmsTemplate(org.springframework.jms.core.JmsTemplate) { 
        connectionFactory = ref(userListenerCredentialsConnectionFactory) 
        destinationResolver = ref(jmsListenerDestinationResolver) 
    } 
    
    jmsListenerMessageListener(org.springframework.jms.listener.adapter.MessageListenerAdapter, ref("myListenerService")) { 
        defaultListenerMethod = "onMessage" 
    } 
    
    standardListenerJmsListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) { 
        connectionFactory = ref(jmsListenerConnectionFactory) 
        destinationResolver = ref(jmsListenerDestinationResolver) 
        messageListener = jmsListenerMessageListener 
        destinationName  = "jms.checkonserver.MessagesQueue" 
    } 
    
  2. package app 
    
    class MyListenerService { 
    
         static transactional = false 
         static scope = "prototype" 
    
    def onMessage(msg) { 
         log.info "JMS msg received." 
         try { 
          String txtmsg = new String(msg as String) 
          log.info txtmsg 
         } catch (e) { 
          log.error e 
         } 
        } 
    } 
    
  3. 設置JMS 聽衆

    • 中的conf

      /春/ resources.groovy

    • 設置JMS 發件人

      • 在CONF

        /彈簧/ resources.groovy:

         jmsSenderConnectionFactory(org.springframework.jndi.JndiObjectFactoryBean) { 
              jndiTemplate = ref(jndiTemplate) 
              jndiName  = "jms.checkonseerver.QueueConnectionFactory" 
             } 
        
             jmsSenderDestinationResolver(org.springframework.jms.support.destination.JndiDestinationResolver) { 
              jndiTemplate = ref(jndiTemplate) 
              cache = false 
             } 
        
             userSenderCredentialsConnectionFactory(org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter){ 
              targetConnectionFactory = ref(jmsSenderConnectionFactory) 
             } 
        
             standardSenderJmsTemplate(org.springframework.jms.core.JmsTemplate) { 
              connectionFactory = ref(userSenderCredentialsConnectionFactory) // 
              destinationResolver = ref(jmsSenderDestinationResolver) 
             } 
        
      • 在服務

        /myJmsSenderService.groovy:

        package app 
        
        import org.springframework.jms.core.MessageCreator 
        
        import javax.jms.JMSException 
        import javax.jms.Message 
        import javax.jms.Session 
        
        class MyJmsSenderService { 
        
            static transactional = false 
            static scope = "prototype" 
        
            def standardSenderJmsTemplate 
        
            def sendMessage(txt) { 
              MessageCreator messageCreator = new MessageCreator() { 
              public Message createMessage(Session session) throws 
              JMSException { 
               return session.createTextMessage(txt) 
              } 
              } 
        
             standardSenderJmsTemplate.send("jms.checkonserver.SendingQueue", messageCreator) 
        
             log.info "JMS message send: ${txt}" 
        
            } 
        }