手摸手系列之---camel ftp监听本地报文目录,并在报文生成后上传到远程第三方ftp服务器实战

本文介绍了如何在SpringBoot 2.4和Camel 3.5.0环境下,配置camel监听本地目录,当生成XML报文后自动将其上传到远程FTP第三方服务器的实践过程。主要涉及Zbus接口实现和XML报文生成代码。
摘要由CSDN通过智能技术生成
前言

版本:
SpringBoot 2.4
camel 3.5.0

上篇文章已经说过项目需求和主要流程,现在已经接收解析xml报文并入库生成Java对象。下一步就是处理完生成的数据生成XML报文,再返回给第三方ftp服务器了。下面看看怎么做。

1. 增加camel配置,本地监听目录和远程第三方ftp服务器URL。
# camel配置
camel:
  # camel ftp服务路由地址
  route:
    id: XMLRoute
    ftp:
      server: sftp://ip:port/AAA/BBB?username=root&password=123456&passiveMode=true&move=backup&moveFailed=error&delay=5000&exceptionHandler=#errorExceptionHandler&onCompletionExceptionHandler=#errorExceptionHandler
#      server: file:e:/test?recursive=true&move=.backup&moveFailed=.error&exceptionHandler=#errorExceptionHandler&onCompletionExceptionHandler=#errorExceptionHandler
  file:
    download:
      local:
        # camel 文件内容下载到本地地址(配置中文乱码)
        address: file:/home/AAA/BBB/
    upload:
      local:
      	# 本地383报文生成目录
        383: file:/home/AAA/BBB/send/383?move=backup&moveFailed=error&delay=5000&exceptionHandler=#errorExceptionHandler&onCompletionExceptionHandler=#errorExceptionHandler
        # 本地385报文生成目录
        385: file:/home/AAA/BBB/send/385?move=backup&moveFailed=error&delay=5000&exceptionHandler=#errorExceptionHandler&onCompletionExceptionHandler=#errorExceptionHandler
      remote:
      	# 远程383报文接收目录
        383: sftp://ip:port/AAA/CCC?username=root&password=123456&passiveMode=true&moveFailed=error&delay=5000&exceptionHandler=#errorExceptionHandler&onCompletionExceptionHandler=#errorExceptionHandler
        # 远程385报文接收目录
        385: sftp://ip:port/AAA/DDD?username=root&password=123456&passiveMode=true&moveFailed=error&delay=5000&exceptionHandler=#errorExceptionHandler&onCompletionExceptionHandler=#errorExceptionHandler

二、主要代码
1. zbus接口实现类。(相当于SpringBoot的Controller层)
package com.yorma.ex.api.impl;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.yorma.dcl.api.DecApi;
import com.yorma.dcl.entity.DecHead;
import com.yorma.entity.YmMsg;
import com.yorma.ex.api.ExApi;
import com.yorma.ex.utils.XmlUtils;
import com.yorma.util.RequestKit;
import io.zbus.rpc.annotation.Param;
import io.zbus.rpc.annotation.Route;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.Date;

import static cn.hutool.core.util.ObjectUtil.isEmpty;
import static cn.hutool.core.util.StrUtil.isBlank;
import static cn.hutool.core.util.StrUtil.isNotBlank;
import static com.yorma.ex.utils.Const.BW383;
import static com.yorma.ex.utils.Const.BW385;

/**
 * @author ZHANGCHAO
 * @date 2021/6/15 10:18
 * @since 1.0.0
 */
@Slf4j
@Route("/dec")
@Component
public class ExApiImpl implements ExApi {
   

    @Autowired
    private DecApi decApi;

    /**
     * 报文上传本地目录383
     */
    @Value("${camel.file.upload.local.383}")
    private String uploadLocal383Path;

    /**
     * 报文上传本地目录385
     */
    @Value("${camel.file.upload.local.385}")
    priv
中文名: Camel 实战 原名: Camel in Action 作者: Claus Ibsen Jonathan Anstey 资源格式: PDF 版本: 英文文字版/更新源代码 出版社: Manning书号: 9781935182368发行时间: 2010年12月 地区: 美国 语言: 英文 简介: 内容介绍: Apache Camel is a Java framework that lets you implement the standard enterprise integration patterns in a few lines of code. With a concise but sophisticated DSL you snap integration logic into your app, Lego-style, using Java, XML, or Scala. Camel supports over 80 common transports such as HTTP, REST, JMS, and Web Services. Camel in Action is a Camel tutorial full of small examples showing how to work with the integration patterns. It starts with core concepts like sending, receiving, routing, and transforming data. It then shows you the entire lifecycle and goes in depth on how to test, deal with errors, scale, deploy, and even monitor your app—details you can find only in the Camel code itself. Written by the developers of Camel, this book distills their experience and practical insights so that you can tackle integration tasks like a pro. 目录: Part 1 First steps 1 Meeting Camel 2 Routing with Camel Part 2 Core Camel 3 Transforming data with Camel 4 Using beans with Camel 5 Error handling 6 Testing with Camel 7 Understanding components 8 Enterprise integration patterns Part 3 Out in the wild 9 Using transactions 10 Concurrency and scalability 11 Developing Camel projects 12 Management and monitoring 13 Running and deploying Camel 14 Bean routing and remoting appendix A Simple, the expression language appendix B Expressions and predicates appendix C The producer and consumer templates appendix D The Camel community appendix E Akka and Camel
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值