oracle aq java jms使用(数据类型为XMLTYPE)

2023-12-17 19:01

本文主要是介绍oracle aq java jms使用(数据类型为XMLTYPE),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

记录一次冷门技术oracle aq的使用

版本

oracle 11g

创建用户

-- 创建用户
create user testaq identified by 123456;
grant connect, resource to testaq;-- 创建aq所需要的权限
grant execute on dbms_aq to testaq;
grant execute on dbms_aqadm to testaq;
begindbms_aqadm.grant_system_privilege('enqueue_any', 'testaq', false);dbms_aqadm.grant_system_privilege('dequeue_any', 'testaq', false);
end;grant execute on dbms_aq to testaq;
grant resource to testaq;
grant connect to testaq;
grant execute any procedure to testaq;
grant aq_administrator_role to testaq;
grant aq_user_role to testaq;
grant execute on dbms_aqadm to testaq;
grant execute on dbms_aq to testaq;
grant execute on dbms_aqin to testaq;
grant create procedure to testaq;
grant create procedure to testaq with admin option;

创建列队表

begindbms_aqadm.create_queue_table(queue_table   => 'testaq.xml_queue_table',queue_payload_type => 'SYS.XMLTYPE',multiple_consumers => false);
end;

创建列队及启动队列

begindbms_aqadm.create_queue (queue_name  => 'testaq.xml_queue',queue_table => 'testaq.xml_queue_table');dbms_aqadm.start_queue(queue_name  =>  'testaq.xml_queue');
end;

停止及删除队列

begindbms_aqadm.stop_queue (queue_name => 'testaq.xml_queue');dbms_aqadm.drop_queue (queue_name => 'testaq.xml_queue');dbms_aqadm.drop_queue_table (queue_table => 'testaq.xml_queue_table');
end;

发送消息

declarer_enqueue_options DBMS_AQ.ENQUEUE_OPTIONS_T;r_message_properties DBMS_AQ.MESSAGE_PROPERTIES_T;v_message_handle RAW(16);o_payload SYS.XMLTYPE;
begino_payload := SYS.XMLTYPE('<ROOT><ROWSET><ROW><APPLYNO>test</APPLYNO></ROW></ROWSET></ROOT>');dbms_aq.enqueue(queue_name  => 'testaq.test_queue',enqueue_options => r_enqueue_options,message_properties => r_message_properties,payload => o_payload,msgid => v_message_handle);commit;
end;

Java接收消息

oracle-aq:jdbcUrl: jdbc:oracle:thin:@localhost:1521:testaqusername: testaqpassword: 123456queueNameUser: testaqqueueName: xml_queue
@Component
@ConfigurationProperties(prefix = "oracle-aq")
@Data
public class OracleAqJmsConfig {private String jdbcUrl;private String username;private String password;private String queueNameUser;private String queueName;
}
import lombok.extern.slf4j.Slf4j;
import oracle.jms.AQjmsAdtMessage;
import oracle.jms.AQjmsDestination;
import oracle.jms.AQjmsFactory;
import oracle.jms.AQjmsSession;
import oracle.xdb.XMLType;
import oracle.xdb.XMLTypeFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import javax.jms.*;
import javax.xml.bind.JAXBException;
import java.util.Properties;@Service
@Slf4j
public class TestOracleAq {@Autowiredprivate OracleAqJmsConfig config;@PostConstructpublic void messageListener() throws JMSException {QueueConnectionFactory queueConnectionFactory = AQjmsFactory.getQueueConnectionFactory(config.getJdbcUrl(), new Properties());QueueConnection conn = queueConnectionFactory.createQueueConnection(config.getUsername(), config.getPassword());AQjmsSession session = (AQjmsSession)conn.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);conn.start();Queue queue = (AQjmsDestination)session.getQueue(config.getQueueNameUser(), config.getQueueName());XMLTypeFactory factory = new XMLTypeFactory();MessageConsumer consumer = session.createConsumer(queue, null, factory, null, false);consumer.setMessageListener(new MessageListener() {@Overridepublic void onMessage(Message message) {AQjmsAdtMessage adtMessage = (AQjmsAdtMessage) message;try {Object adtPayload = adtMessage.getAdtPayload();XMLType xmlType = (XMLType)adtPayload;saveXml(xmlType.getStringVal());log.info("接收到oracle aq数据:{}", xmlType.getStringVal());} catch (Exception e) {log.error("", e);}}});}public void saveXml(String xml) throws JAXBException {// todo ...}}

依赖

在oracle安装目录中查找这些依赖
在这里插入图片描述

<!-- oracle aq --><dependency><groupId>com.oracle</groupId><artifactId>ojdbc6</artifactId><version>11.1.0.7.0</version><scope>system</scope><systemPath>${project.basedir}/libs/ojdbc6.jar</systemPath>
</dependency>
<dependency><groupId>com.oracle</groupId><artifactId>jmscommon</artifactId><version>1.0</version><scope>system</scope><systemPath>${project.basedir}/libs/jmscommon.jar</systemPath>
</dependency>
<dependency><groupId>com.oracle</groupId><artifactId>orai18n</artifactId><version>11.1.0.7.0</version><scope>system</scope><systemPath>${project.basedir}/libs/orai18n.jar</systemPath>
</dependency>
<dependency><groupId>com.oracle</groupId><artifactId>jta</artifactId><version>1.0</version><scope>system</scope><systemPath>${project.basedir}/libs/jta.jar</systemPath>
</dependency>
<dependency><groupId>com.oracle</groupId><artifactId>aqapi_g</artifactId><version>1.0</version><scope>system</scope><systemPath>${project.basedir}/libs/aqapi_g.jar</systemPath>
</dependency>
<dependency><groupId>oracle.xdb</groupId><artifactId>xdb</artifactId><version>21.9.0.0</version><scope>system</scope><systemPath>${project.basedir}/libs/xdb.jar</systemPath>
</dependency>
<!-- oracle aq -->

这篇关于oracle aq java jms使用(数据类型为XMLTYPE)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/505481

相关文章

Spring Boot项目部署命令java -jar的各种参数及作用详解

《SpringBoot项目部署命令java-jar的各种参数及作用详解》:本文主要介绍SpringBoot项目部署命令java-jar的各种参数及作用的相关资料,包括设置内存大小、垃圾回收... 目录前言一、基础命令结构二、常见的 Java 命令参数1. 设置内存大小2. 配置垃圾回收器3. 配置线程栈大小

SpringBoot实现微信小程序支付功能

《SpringBoot实现微信小程序支付功能》小程序支付功能已成为众多应用的核心需求之一,本文主要介绍了SpringBoot实现微信小程序支付功能,文中通过示例代码介绍的非常详细,对大家的学习或者工作... 目录一、引言二、准备工作(一)微信支付商户平台配置(二)Spring Boot项目搭建(三)配置文件

解决SpringBoot启动报错:Failed to load property source from location 'classpath:/application.yml'

《解决SpringBoot启动报错:Failedtoloadpropertysourcefromlocationclasspath:/application.yml问题》这篇文章主要介绍... 目录在启动SpringBoot项目时报如下错误原因可能是1.yml中语法错误2.yml文件格式是GBK总结在启动S

鸿蒙中@State的原理使用详解(HarmonyOS 5)

《鸿蒙中@State的原理使用详解(HarmonyOS5)》@State是HarmonyOSArkTS框架中用于管理组件状态的核心装饰器,其核心作用是实现数据驱动UI的响应式编程模式,本文给大家介绍... 目录一、@State在鸿蒙中是做什么的?二、@Spythontate的基本原理1. 依赖关系的收集2.

Python基础语法中defaultdict的使用小结

《Python基础语法中defaultdict的使用小结》Python的defaultdict是collections模块中提供的一种特殊的字典类型,它与普通的字典(dict)有着相似的功能,本文主要... 目录示例1示例2python的defaultdict是collections模块中提供的一种特殊的字

Spring中配置ContextLoaderListener方式

《Spring中配置ContextLoaderListener方式》:本文主要介绍Spring中配置ContextLoaderListener方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录Spring中配置ContextLoaderLishttp://www.chinasem.cntene

java实现延迟/超时/定时问题

《java实现延迟/超时/定时问题》:本文主要介绍java实现延迟/超时/定时问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Java实现延迟/超时/定时java 每间隔5秒执行一次,一共执行5次然后结束scheduleAtFixedRate 和 schedu

Java Optional避免空指针异常的实现

《JavaOptional避免空指针异常的实现》空指针异常一直是困扰开发者的常见问题之一,本文主要介绍了JavaOptional避免空指针异常的实现,帮助开发者编写更健壮、可读性更高的代码,减少因... 目录一、Optional 概述二、Optional 的创建三、Optional 的常用方法四、Optio

C++ Sort函数使用场景分析

《C++Sort函数使用场景分析》sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变,如果某些场景需要保持相同元素间的相对顺序,可使... 目录C++ Sort函数详解一、sort函数调用的两种方式二、sort函数使用场景三、sort函数排序

Spring Boot项目中结合MyBatis实现MySQL的自动主从切换功能

《SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能》:本文主要介绍SpringBoot项目中结合MyBatis实现MySQL的自动主从切换功能,本文分步骤给大家介绍的... 目录原理解析1. mysql主从复制(Master-Slave Replication)2. 读写分离3.