Grails JMS插件到WebLogic JMS服务器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Grails JMS插件到WebLogic JMS服务器相关的知识,希望对你有一定的参考价值。
有没有人配置Grails 2.x JMS插件来发送/接收消息到远程WebLogic JMS服务器?我已经尝试过这样的resources.groovy配置而没有运气:
jmsConnectionFactory(InitialContext, [
"INITIAL_CONTEXT_FACTORY": "weblogic.jndi.WLInitialContextFactory",
"PROVIDER_URL": "t3://remote-host:7001",
"SECURITY_PRINCIPAL": "weblogic",
"SECURITY_CREDENTIALS": "weblogic"])
答案
关于使用远程Weblogic服务器在Grails中发送/接收JMS,没有太多关于完整答案的资源,因此我在2 - 3年前找到了一个可行的解决方案,无需任何插件。
- 确保至少Weblogic wlthint3client.jar位于lib目录中。
- 设置JMS侦听器:
在conf / spring / resources.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" }
在services / myListenerService.groovy中: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 } } }
- 设置JMS发件人:
在conf / spring / 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}" } }
以上是关于Grails JMS插件到WebLogic JMS服务器的主要内容,如果未能解决你的问题,请参考以下文章
在 WebLogic 中配置 JMS 消息大小:weblogic.socket.MaxMessageSizeExceededException