Aliware MQ 使用代理
来源:互联网 发布:lte网络优化案例 编辑:程序博客网 时间:2024/06/06 12:34
Aliware MQ 使用中遇到代理问题
在学习使用Aliware MQ过程中,遇到了如下错误。
Exception in thread “main”
com.aliyun.openservices.ons.api.exception.ONSClientException: Can not
find name server, May be your network problem. See
http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&namesrv_not_exist
for further details. at
com.aliyun.openservices.ons.api.impl.rocketmq.ONSClientAbstract.(ONSClientAbstract.java:70)
at
com.aliyun.openservices.ons.api.impl.rocketmq.ProducerImpl.(ProducerImpl.java:31)
at
com.aliyun.openservices.ons.api.impl.ONSFactoryImpl.createProducer(ONSFactoryImpl.java:20)
at
com.aliyun.openservices.ons.api.ONSFactory.createProducer(ONSFactory.java:45)
at
com.aliyun.openservices.client.ProducerClien.main(ProducerClien.java:44)
异常原因是因为网络使用了代理,需要在代码中加入代理参数。
Java中设置代理可以使用Authenticator类,但Authenticator类是一个抽象类,所以需要实现一下:
public class BasicAuthenticator extends Authenticator {
StringuserName;
String password;
public BasicAuthenticator(String userName, String password) {
this.userName = userName;
this.password = password;
}
/**
* Called when password authorization is needed. Subclasses should override the default implementation, which
* returns null.
*
* @return The PasswordAuthentication collected from the user, or null if none is provided.
*/
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userName, password.toCharArray());
}
}
在业务类中加入以下代码块:
static{
System.setProperty(“http.proxyHost”, “proxy.*.com”);
System.setProperty(“http.proxyPort”, “8080”);
Authenticator.setDefault(new BasicAuthenticator(“XXX”, “XXXX”));
}
- Aliware MQ 使用代理
- Aliware-MQ消息队列技术架构与最佳实践
- MQ使用
- 使用MQ JMS
- MQ集群的使用
- MQ使用经验总结
- MQ使用所得
- Active MQ使用
- mq使用心得
- MQ使用经验
- 为什么需要使用MQ?
- 为什么需要使用MQ?
- Active MQ使用场景
- Active MQ 使用
- MQ--为什么使用它?
- MQ使用经验总结
- Active MQ的使用
- WebSphere MQ使用
- 自己的考研之路
- 【公司项目总结】(三)---解决XX Cannotbe resolved to a type 报错思路
- db2 常用操作指令
- Python安装及Sublime text 3使用
- summary
- Aliware MQ 使用代理
- POJ
- summary
- [网络流24题]分配问题
- nginx配置说明
- C# 控件如何获取事件已经注册的方法
- summary
- bzoj4512
- oracle thin和oci 区别