1、windows安装activemq
这里参考:ActiveMQ本地安装及启动(Windows)_本地运行activemq-CSDN博客
在安装的过程中发现报错:
jvm 1 | WrapperSimpleApp: Unable to locate the class org.apache.activemq.console.Main: java.lang.UnsupportedClassVersionError: org/apache/activemq/console/Main has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
原因是window的java版本不匹配,5.18.5对应的是java11,而本机windows的环境是java8,这里下载之前的版本
找个合适的就好了,这里用的是5.15.15
考虑到windows启用防火墙的情况,所以对防火墙增加规则让端口暴露:
这里选择端口并用activemq的默认端口61616
2、ftp的配置
这里参考:Windows—FTP配置(超详细流程)_windows ftp-CSDN博客
在我配置完ftp后启动linux的程序去连接activemq和ftp是没有问题的,但是在ftp上传图片的时候失败;
这是我ftp上传图片的代码,利用curl库进行上传:
std::string ftp_upload_image(const std::string& file, std::string& stream_id, std::string& s_ftp_url,
std::string& s_ftp_username, std::string& s_ftp_password, std::string& s_tomcat_ip, std::string& type_flag)
{
string path{};
curl_global_init(CURL_GLOBAL_ALL);
CURL* curl = curl_easy_init();
// 启用详细输出
//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, (long)1);
curl_easy_setopt(curl, CURLOPT_USERNAME, s_ftp_username.data());
curl_easy_setopt(curl, CURLOPT_PASSWORD, s_ftp_password.data());
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L);
string url;
string cur_date = url_datetime();
string uuid = create_uuid(true);
Rjson::format_string(url, "%s/upload/%s/%s/%s.jpg", s_ftp_url.data(), type_flag.data(), stream_id.data(), uuid.data());
struct WriteThis upload;
upload.readptr = file.data();
upload.sizeleft = file.size();
curl_easy_setopt(curl, CURLOPT_URL, url.data());
curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
curl_easy_setopt(curl, CURLOPT_READDATA, &upload);
CURLcode rc = curl_easy_perform(curl);
if (rc) {
LOGE(ImageStore) << "[" << stream_id << "]" << "!!! ftp Failed to upload: " << url.data() << " error: " << rc;
return path;
}
string tomcat_ip;
Rjson::format_string(tomcat_ip, "%s/upload/%s/%s/%s.jpg", s_tomcat_ip.data(), type_flag.data(), stream_id.data(), uuid.data());
curl_easy_cleanup(curl);
curl_global_cleanup();
path = tomcat_ip;
//format_string(path, "upload/%s/%s/%s.jpg", cur_date.data(), stream_id.data(), uuid.data());
return path;
}
这里curl_easy_perform返回7,连接失败,那么取消前面的注释,将curl的调试信息打印出来如下:
* About to connect() to 192.168.8.34 port 21 (#0)
* Trying 192.168.8.34...
* Connected to 192.168.8.34 (192.168.8.34) port 21 (#0)
< 220 Microsoft FTP Service
> USER tuling
< 331 Password required
> PASS 123456
< 230 User logged in.
> PWD
< 257 "/" is current directory.
* Entry path is '/'
> CWD upload
* ftp_perform ends with SECONDARY: 0
< 250 CWD command successful.
> CWD preview_image
< 250 CWD command successful.
> CWD 58361F9A3B8231FCAD04191900000000
< 550 The system cannot find the file specified.
> MKD 58361F9A3B8231FCAD04191900000000
< 257 "58361F9A3B8231FCAD04191900000000" directory created.
> CWD 58361F9A3B8231FCAD04191900000000
< 250 CWD command successful.
> EPSV
* Connect data stream passively
< 229 Entering Extended Passive Mode (|||7507|)
* Trying 192.168.8.34...
* Connecting to 192.168.8.34 (192.168.8.34) port 7507
* Connection timed out
* Failed connect to 192.168.8.34:21; Connection timed out
* Failed EPSV attempt. Disabling EPSV
> PASV
< 227 Entering Passive Mode (192,168,8,34,29,89).
* Trying 192.168.8.34...
* Connecting to 192.168.8.34 (192.168.8.34) port 7513
* Connection timed out
* Failed connect to 192.168.8.34:21; Connection timed out
* Closing connection 0
发现是ftp采用的是被动模式传输文件,控制端口21虽然开发给linux程序,但是数据传输端口被防火墙挡住了,对于数据连接的端口是1024-65535范围内的随机端口,考虑到当前项目的需求,这里减少端口的范围。
在之前创建的ftp站点修改端口范围:
但是发现这里是灰色的无法修改,可以从上面的目录来修改。
这里就可以更改了,我这里将端口范围修改为5000-6000
修改完后再次执行linux的程序发现配置并没有生效,这是因为修改完配置后需要重启ftp的服务。
重启之后linux程序便可以正常连接ftp和activemq了。
3、捷径
我直接关闭windows防火墙,全都好了!!!!