发送信息到Tibco Queue的完整代码。

package com.jms;import java.util.Enumeration;
import java.util.Properties;import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.QueueBrowser;
import javax.jms.Session;
import javax.naming.Context;
import javax.naming.NamingException;
import org.springframework.context.annotation.Bean;
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.core.BrowserCallback;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.jms.support.destination.DestinationResolver;
import org.springframework.jms.support.destination.JndiDestinationResolver;
import org.springframework.jndi.JndiObjectFactoryBean;
import org.springframework.jndi.JndiTemplate;
import com.tibco.tibjms.Tibjms;
import com.tibco.tibjms.TibjmsSSL;public class TibcoQueueTest {private String queueName = "";private String tibjmsProviderUrl = "";private String tibConnectionFactoryJNDI = "";private String tibjmsHostName = "";private String tibjmsSSLIdentity = "";private static String tibjmsSSLPassword = "";private JmsTemplate jmsTemplate;private TibcoQueueTest() {try {JndiTemplate jndiTemplate = jndiTemplate();JndiObjectFactoryBean jndiBean = jmsConnectionFactory(jndiTemplate);ConnectionFactory connectionFactory = (ConnectionFactory) jndiBean.getObject();connectionFactory = cachingConnectionFactory(connectionFactory);DestinationResolver destinationResolver = destinationResolver(jndiTemplate);jmsTemplate = jmsTemplate(connectionFactory, destinationResolver);} catch (Exception e) {e.printStackTrace();}}public static void main(String[] args) throws Exception {TibcoQueueTest tibcoQueueTest = new TibcoQueueTest();tibcoQueueTest.sendMessageToTibcoQueue("test message");
//  tibcoQueueTest.getQueueCount();
//  tibcoQueueTest.clearQueue();}public void clearQueue() {for (int i=0; i<20 ; i++) {Thread thread = new Thread(()->{ while(true) {Message message = jmsTemplate.receive();System.out.println(message);}});thread.start();}}public Integer getQueueCount() {Integer count = jmsTemplate.browse(new BrowserCallback<Integer>() {public Integer doInJms(final Session session, final QueueBrowser browser) throws JMSException {int counter = 0;try {Enumeration enumeration = browser.getEnumeration();while (enumeration.hasMoreElements()) {enumeration.nextElement();counter += 1;System.out.println(counter);}return counter;} catch (Exception e) {e.printStackTrace();counter = -1; // this will mean error and logs can be// checked}return counter;}});System.out.println("Queue size is " + count);return count;}public JndiTemplate jndiTemplate() {Properties environment = new Properties();environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.tibco.tibjms.naming.TibjmsInitialContextFactory");environment.put(Context.PROVIDER_URL, tibjmsProviderUrl);environment.put("queue." + queueName, queueName);environment.put("com.tibco.tibjms.naming.security_protocol", "ssl");environment.put("com.tibco.tibjms.naming.ssl_identity", tibjmsSSLIdentity);environment.put("com.tibco.tibjms.naming.ssl_password", tibjmsSSLPassword);environment.put("com.tibco.tibjms.naming.ssl_vendor", "j2se");environment.put("com.tibco.tibjms.naming.ssl_enable_verify_host", "false");environment.put("com.tibco.tibjms.naming.ssl_expected_hostname", tibjmsHostName);environment.put("com.tibco.tibjms.naming.ssl.enable_verify_hostname", "false");environment.put("com.tibco.tibjms.ssl.password", tibjmsSSLPassword);return new JndiTemplate(environment);}public JndiObjectFactoryBean jmsConnectionFactory(JndiTemplate jndiTemplate) throws IllegalArgumentException, NamingException {JndiObjectFactoryBean bean = new JndiObjectFactoryBean();bean.setJndiTemplate(jndiTemplate);bean.setJndiName(tibConnectionFactoryJNDI);bean.setExpectedType(ConnectionFactory.class);bean.afterPropertiesSet();return bean;}public ConnectionFactory cachingConnectionFactory(ConnectionFactory connectionFactory) {CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();cachingConnectionFactory.setTargetConnectionFactory(connectionFactory);cachingConnectionFactory.setSessionCacheSize(20);cachingConnectionFactory.setReconnectOnException(true);cachingConnectionFactory.afterPropertiesSet();return cachingConnectionFactory;}@Beanpublic DestinationResolver destinationResolver(JndiTemplate jndiTemplate) {JndiDestinationResolver resolver = new JndiDestinationResolver();resolver.setJndiTemplate(jndiTemplate);resolver.setFallbackToDynamicDestination(true);return resolver;}public JmsTemplate jmsTemplate(ConnectionFactory connectionFactory, DestinationResolver destinationResolver) {MyJMSTemplate template = new MyJMSTemplate();template.setConnectionFactory(connectionFactory);template.setDestinationResolver(destinationResolver);template.setDefaultDestinationName(queueName);template.afterPropertiesSet();return template;}public void sendMessageToTibcoQueue(String message) throws Exception {jmsTemplate.send(new MessageCreator() {@Overridepublic Message createMessage(Session session) throws JMSException {System.out.println("send message:" + message);return session.createTextMessage(message);}});}private static class MyJMSTemplate extends JmsTemplate {@Overrideprotected Connection createConnection() throws JMSException {TibjmsSSL.setPassword(tibjmsSSLPassword.toCharArray());TibjmsSSL.setDebugTraceEnabled(false);TibjmsSSL.setVerifyHost(false);TibjmsSSL.setVerifyHostName(false);Tibjms.setPingInterval(0);TibjmsSSL.setDebugTraceEnabled(false);return getConnectionFactory().createConnection();}}}

Java Spring连接Tibco Queue 总结相关推荐

  1. java c3p0 存储过程_JAVA Spring 连接池 调用 Oracle 存储过程的问题?

    求助,JAVA Spring 连接池 调用 Oracle 存储过程的问题?在Spring中配置了c3P0的连接池,在调用Oracle的存储过程时,报错[code]java.lang.ClassCast ...

  2. java redis集群连接池_(08)redis之使用java客户端、spring连接redis、redis集群示例...

    一.java代码连接 1.新建工程,并引入以下包: jedis-2.7.0.jar.commons-pool2-2.3.jar.junit-4.10.jar 2.单实例连接 /*** 单实例连接*/@ ...

  3. 最新Kafka教程(包含kafka部署与基本操作、java连接kafka、spring连接kafka以及使用springboot)

    最新Kafka教程(包含kafka部署与基本操作.java连接kafka.spring连接kafka以及使用springboot) 欢迎转载,转载请注明网址:https://blog.csdn.net ...

  4. java spring框架 注解_史上最全的java spring注解

    史上最全的java spring注解,没有之一 注解是个好东西,但好东西我们也是看见过,整理过,理解过,用过才知道好.不求我们每个都记住,但求保有印象,在需要的时候能提取出来再查找相关资料,平时工作就 ...

  5. java spring cloud版b2b2c社交电商spring cloud分布式微服务:分布式配置中心

    JAVASpring Cloud大型企业分布式微服务云构建的B2B2C电子商务平台源码请加企鹅求求:一零三八七七四六二六.Spring Cloud Config是Spring Cloud团队创建的一个 ...

  6. Java Spring Boot 2.0 实战之制作Docker镜像并推送到Docker Hub和阿里云仓库

    内容摘要:大规模集群快速部署Java应用,需要制作Docker镜像,本次课程详细介绍如何制作Java程序的Docker镜像文件,深入解析DockerFile核心参数,以及实践演练把我们制作的Docke ...

  7. Java Spring Data Redis实战与配置参数详解 application.properties...

    Redis作为开源分布式高并发缓存,使用范围非常广泛,主流互联网公司几乎都在使用. Java Spring Boot 2.0实战开发Redis缓存可以参考下面的步骤,Redis安装可以直接使用Linu ...

  8. @async注解_史上最全的java spring注解

    史上最全的java spring注解,没有之一 注解是个好东西,但好东西我们也是看见过,整理过,理解过,用过才知道好.不求我们每个都记住,但求保有印象,在需要的时候能提取出来再查找相关资料,平时工作就 ...

  9. spring连接jdbc_在Spring JDBC中添加C3PO连接池

    spring连接jdbc 连接池是一种操作,其中系统会预先初始化将来要使用的连接. 这样做是因为在使用时创建连接是一项昂贵的操作. 在这篇文章中,我们将学习如何在Spring JDBC中创建C3P0连 ...

最新文章

  1. 【Azure Services Platform Step by Step-第14篇】使用Azure版的ASP.NET Application Providers
  2. python小游戏代码大全-20行python代码的入门级小游戏的详解
  3. oracle中sql行数的计算,Oracle技术网—如何利用DBMS_SQL包和游标计算当前用户下所有表的行数...
  4. redis源码学习笔记目录
  5. dj鲜生-让应用的模型类生效,搬家到云服务器-非本地操作
  6. Smart/400开发上手2: COBOL批处理程序处理过程
  7. Ubuntu提示软件更新
  8. 判断包含字符当中包含小数点_Python|提取包含指定文本的行到一个文本文件(字符串或正则)...
  9. 网页制作初期,必须的东西
  10. 单个产品出库扣减库存
  11. 华人AI学者大盘点:清华培养了最多的高层次人才,韩家炜、吴恩达论文被引数“登顶”
  12. Python 安装pytz
  13. lightoj 1224(trie)
  14. 个人博客详细文章目录索引(持续更新)
  15. BZOJ3168. 【HEOI2013】钙铁锌硒维生素
  16. 三井化学将增加TAFMER™高性能弹性体产能
  17. 激活window10专业版的方法。
  18. python——文件对比
  19. 国企招聘属于事业单位吗
  20. 遮挡人脸识别:基于Python3.8+Tensorflow2.2人脸遮挡情况的人脸识别

热门文章

  1. SQL表名,应该用复数还是单数
  2. mysql中delete from in子查询删除失败
  3. @Override must override a superclass method
  4. LZW数据压缩算法的原理分析
  5. 适合初学者的struts简单案例
  6. 分布式数据库clickhouse、tidb、palo对比
  7. 基于CentOS 7 安装Percona XtraDB Cluster(PXC) 5.7
  8. HTML 中多媒体设置:1、滚动字幕及滚动图片的设置 2、音乐视频的插入
  9. 你还在用 Date?建议使用 LocalDateTime 了!
  10. 【kotin】统计字符串中的字母数(拓展函数)