当前位置: 首页 > news >正文

基于jsp的电子商务网站开发凌河锦州网站建设

基于jsp的电子商务网站开发,凌河锦州网站建设,郑州郑州网站建设河南做网站公司哪家好,三明网站设计文章目录 1.RPC客户端2.RabbitMQ连接信息实体类3.XML工具类 本文档只是为了留档方便以后工作运维#xff0c;或者给同事分享文档内容比较简陋命令也不是特别全#xff0c;不适合小白观看#xff0c;如有不懂可以私信#xff0c;上班期间都是在得 直接上代码了 1.RPC客户端 … 文章目录 1.RPC客户端2.RabbitMQ连接信息实体类3.XML工具类 本文档只是为了留档方便以后工作运维或者给同事分享文档内容比较简陋命令也不是特别全不适合小白观看如有不懂可以私信上班期间都是在得 直接上代码了 1.RPC客户端 RPC客户端 /*** ClassName: RPCClient* Description: RPC 客户端* Author: XHao* Date: 2024/8/30 11:14*/ public class RPCClient {private Connection connection;private Channel channel;private String requestQueueName XYG.HS.MES.PRD.CNXsvr;private String replyQueueName;public RPCClient() {}public RPCClient(XygMqIesConnInfo xygMqIesConnInfo) throws IOException, TimeoutException {//建立一个连接和一个通道并为回调声明一个唯一的回调队列ConnectionFactory factory new ConnectionFactory();factory.setHost(xygMqIesConnInfo.getHost());factory.setPort(xygMqIesConnInfo.getPort());factory.setUsername(xygMqIesConnInfo.getUserName());factory.setPassword(xygMqIesConnInfo.getPwd());factory.setVirtualHost(IES);try {connection factory.newConnection();System.err.println(创建通道);channel connection.createChannel();System.err.println(创建成功);}catch (Exception e){System.err.println(报错信息e.getMessage());}//定义一个临时变量的接受队列名System.err.println(定义一个临时变量的接受队列名);replyQueueName channel.queueDeclare().getQueue();}//发送RPC请求public String call(String message) throws IOException, InterruptedException {//生成一个唯一的字符串作为回调队列的编号String corrId UUID.randomUUID().toString();//发送请求消息消息使用了两个属性replyto和correlationId//服务端根据replyto返回结果客户端根据correlationId判断响应是不是给自己的AMQP.BasicProperties props new AMQP.BasicProperties.Builder().correlationId(corrId).replyTo(replyQueueName).build();//发布一个消息requestQueueName路由规则System.err.println(发布一个消息);System.err.println(消息内容);System.err.println( message );System.err.println();System.err.println();System.err.println();System.err.println(回调队列的编号);System.err.println(请求时间new Date());System.err.println( correlationId::props.getCorrelationId() );System.err.println( ReplyTo::props.getReplyTo() );channel.basicPublish(, requestQueueName, props, message.getBytes(StandardCharsets.UTF_8));//由于我们的消费者交易处理是在单独的线程中进行的因此我们需要在响应到达之前暂停主线程。//这里我们创建的 容量为1的阻塞队列ArrayBlockingQueue因为我们只需要等待一个响应。final BlockingQueueString response new ArrayBlockingQueueString(1);//获取响应消息System.err.println(获取响应消息);channel.basicConsume(replyQueueName, true, new DefaultConsumer(channel) {Overridepublic void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,byte[] body) throws IOException {//检查它的correlationId是否是我们所要找的那个if (properties.getCorrelationId().equals(corrId)) {//如果是则响应BlockingQueueresponse.offer(new String(body, UTF-8));}}});return response.take();}public void close() throws IOException {connection.close();}public static JSONObject getResult(XygMqIesConnInfo xygMqIesConnInfo, String msg) {if (Objects.isNull(xygMqIesConnInfo) || Objects.isNull(msg)) {return null;}RPCClient fibonacciRpc null;String response null;try {fibonacciRpc new RPCClient(xygMqIesConnInfo);response fibonacciRpc.call(msg);System.err.println(响应消息response);} catch (IOException | InterruptedException e) {e.printStackTrace();throw new RuntimeException(RPC调用异常);} catch (TimeoutException e) {e.printStackTrace();throw new RuntimeException(RPC调用超时);} finally {if (fibonacciRpc ! null) {try {fibonacciRpc.close();} catch (IOException ignore) {}}}return XmlUtil.xmlToJson(response);} }2.RabbitMQ连接信息实体类 RabbitMQ连接信息实体类 /*** ClassName: XygMqIESConnectionInfo* Description: RabbitMQ连接信息* Author: XHao* Date: 2024/8/22 17:07*/ Data JsonInclude(JsonInclude.Include.NON_NULL) TableName(xyg_mq_ies_conn_info) ApiModel(value 连接信息对象, description IES RabbitMQ连接信息表) public class XygMqIesConnInfo {private static final long serialVersionUID 1L;TableId(value ID, type IdType.AUTO)private Long id;ApiModelProperty(value 园区ID)private String parkId;ApiModelProperty(value 车间编码)private String workshopCode;ApiModelProperty(value 主机地址)private String host;ApiModelProperty(value 端口)private Integer port;ApiModelProperty(value 用户名)private String userName;ApiModelProperty(value 密码)private String pwd;ApiModelProperty(value 队列名称)private String queueName;ApiModelProperty(value 交换机名称)private String exchangeName;ApiModelProperty(value 路由键)private String routingKey; }3.XML工具类 XML工具类 /*** ClassName: XmlUtil* Description: xml 解析与生成工具类* Author: XHao* Date: 2024/8/20 14:28*/ public class XmlUtil {/*** XML节点转换JSON对象** param element 节点* param object 新的JSON存储* return JSON对象*/private static JSONObject xmlToJson(Element element, JSONObject object) {ListElement elements element.elements();for (Element child : elements) {Object value object.get(child.getName());Object newValue;if (child.elements().size() 0) {JSONObject jsonObject xmlToJson(child, new JSONObject(true));if (!jsonObject.isEmpty()) {newValue jsonObject;} else {newValue child.getText();}} else {newValue child.getText();}ListAttribute attributes child.attributes();if (!attributes.isEmpty()) {JSONObject attrJsonObject new JSONObject();for (Attribute attribute : attributes) {attrJsonObject.put(attribute.getName(), attribute.getText());attrJsonObject.put(content, newValue);}newValue attrJsonObject;}if (newValue ! null) {if (value ! null) {if (value instanceof JSONArray) {((JSONArray) value).add(newValue);} else {JSONArray array new JSONArray();array.add(value);array.add(newValue);object.put(child.getName(), array);}} else {object.put(child.getName(), newValue);}}}return object;}/*** XML字符串转换JSON对象** param xmlStr XML字符串* return JSON对象*/public static JSONObject xmlToJson(String xmlStr) {JSONObject result new JSONObject(true);SAXReader xmlReader new SAXReader();try {Document document xmlReader.read(new StringReader(xmlStr));Element element document.getRootElement();return xmlToJson(element, result);} catch (Exception e) {e.printStackTrace();}return result;}/*** XML文件转换JSON对象** param xmlString xml字符串* param node 选择节点* return JSON对象*/public static JSONObject xmlToJson(String xmlString, String node) {JSONObject result new JSONObject(true);SAXReader xmlReader new SAXReader();try {//将给定的String文本解析为XML文档并返回新创建的documentorg.dom4j.Document document DocumentHelper.parseText(xmlString); // Document document xmlReader.read(file);Element element;if (StringUtils.isBlank(node)) {element document.getRootElement();} else {element (Element) document.selectSingleNode(node);}return xmlToJson(element, result);} catch (Exception e) {e.printStackTrace();}return result;}/*** 生成xml格式的字符串** return*/public static String createXmlString(XmlParam xmlParam) {//创建document对象org.dom4j.Document document DocumentHelper.createDocument();//设置编码document.setXMLEncoding(UTF-8);//创建根节点Element message document.addElement(Message);// 开始组装 Header 节点// 在 Header 节点下加入子节点Element header message.addElement(Header);// 组装固定值for (HeaderEnum h : HeaderEnum.values()) {Element childNode header.addElement(h.name());childNode.setText(h.getValue());}// 组装传参值MapString, String headerMap JSONObject.parseObject(JSONObject.toJSONString(xmlParam.getHeader()), Map.class);headerMap.forEach((k, v) - {Element childNode header.addElement(k.toUpperCase());childNode.setText(v);});// 组装事务ID唯一值:当前时间戳Element transactionId header.addElement(TRANSACTIONID);SimpleDateFormat sdf new SimpleDateFormat(yyyyMMdd);transactionId.setText(sdf.format(new Date()) String.valueOf(Calendar.getInstance().getTimeInMillis()));Element listener header.addElement(listener);listener.setText(QueueListener);// 开始组装 Body 节点Element body message.addElement(Body);MapString, String bodyMap JSONObject.parseObject(JSONObject.toJSONString(xmlParam.getBody()), Map.class);bodyMap.forEach((k, v) - {if (Objects.isNull(v)) {return;}Element childNode body.addElement(k.toUpperCase());childNode.setText(v);});//将document对象转换成字符串String xml document.asXML();// 去掉 XML 声明if (xml.startsWith(?xml)) {xml xml.substring(xml.indexOf() 1);}return xml;}如果点赞多评论多会更新详细教程待补充。
http://www.hkea.cn/news/14262314/

相关文章:

  • 杨浦网站建设哪家好福州网站制作有限公司
  • 无锡有人代做淘宝网站吗浏览器的网址是多少
  • com域名的网址有哪些长沙关键词优化平台
  • 网站收录 百度自动增加参数wordpress app开发教程
  • 菜单微网站网页布局名称
  • 深圳网站设计公司费用大概多少深圳seo公司助力网络营销飞跃
  • 怎么找个人搭建网站学生个人静态网页制作过程
  • 房产中介如何做网站巢湖路桥建设集团网站
  • 石材企业网站源码网站建设五行属什么
  • 网站后缀有什么区别wordpress 伪静态 win
  • 信息网站方案互联网行业黑话
  • 江苏同隆建设集团有限公司网站外贸行业网站推广
  • 外贸网站建设哪家合适石家庄规划
  • 怎样建设智能网站临沂建设局官方网站
  • 网站seo内容优化网站假备案举报
  • 上海建设银行网站静安支行wordpress关闭前端公共库
  • 随身wifi网站设置国庆节网页设计素材
  • 网站虚拟主机管理公司网页制作哪家强
  • 洛阳网站建设价格低做学校法人年度报告的网站
  • 浙江 网站备案万网域名注册官网中文域名
  • 网站推广的方式手段有哪些门户网站开发研究报告
  • 个人网站建设模板简洁图片自命题规划一个企业网站
  • 广西网站建设liluokj单位网站开发费用入什么费用
  • 卡片式网站模板下载适合用dedecms做的网站
  • 如何建电子商务网站易语言怎么用网站做背景音乐
  • 假发网站建设常州网站建设设计
  • 网站建设页面框架wordpress接入api
  • php能自己做网站吗wordpress批注功能
  • 阿凡达网站建设网moodle ual wordpress
  • 产品如何做网站地图百度分享wordpress