我正在尝试编写一个java发布程序,将单个消息发送到事件中心。但是,当我尝试执行它时,我得到一个连接中止错误。我正在使用下面链接(azure-eventhubs)和版本0.9.0中指定的maven依赖项。下面是我想要遵循的链接和主要方法。
https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-java-ephcs-getstarted
public static void main(String[] args)
throws ServiceBusException, ExecutionException, InterruptedException, IOException {
final String namespaceName = "<namespace name>";
final String eventHubName = "<created with same name as namespace>";
final String sasKeyName = "RootManageSharedAccessKey";
final String sasKey = "<primary key from shared acccess policies>";
ConnectionStringBuilder connStr = new ConnectionStringBuilder(namespaceName, eventHubName, sasKeyName, sasKey);
byte[] payloadBytes = "Test AMQP message from JMS, Yaay it works".getBytes("UTF-8");
EventData sendEvent = new EventData(payloadBytes);
EventHubClient ehClient = EventHubClient.createFromConnectionStringSync(connStr.toString());
ehClient.sendSync(sendEvent);
}
这是我得到的错误的堆栈跟踪。任何帮助表示赞赏。
error[connection aborted]
Exception in thread "main" com.microsoft.azure.servicebus.ServiceBusException: connection aborted
at com.microsoft.azure.servicebus.ExceptionUtil.toException(ExceptionUtil.java:93)
at com.microsoft.azure.servicebus.MessagingFactory.onConnectionError(MessagingFactory.java:187)
at com.microsoft.azure.servicebus.amqp.ConnectionHandler.onTransportError(ConnectionHandler.java:105)
at org.apache.qpid.proton.engine.BaseHandler.handle(BaseHandler.java:191)
at org.apache.qpid.proton.engine.impl.EventImpl.dispatch(EventImpl.java:108)
at org.apache.qpid.proton.reactor.impl.ReactorImpl.dispatch(ReactorImpl.java:309)
at org.apache.qpid.proton.reactor.impl.ReactorImpl.process(ReactorImpl.java:276)
at com.microsoft.azure.servicebus.MessagingFactory$RunReactor.run(MessagingFactory.java:340)
at java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:1)
总结上述评论,似乎是issue page评论列表末尾的类似GitHub的Azure EventHub SDK for Java问题。 但是,根据我的经验,似乎有些防火墙&amp;防病毒软件阻止了SSL上的amqp连接。正如@Hemanthmeka所说,这个问题是由他办公室的防火墙造成的。
答案 1 :(得分:0)
是的,这绝对是防火墙问题,您需要使用以下代码来帮助您在将数据写入EventHub时解决连接问题。
希望这会有所帮助!
final ConnectionStringBuilder connStr = new ConnectionStringBuilder()
.setNamespaceName("Your namespace name")
.setEventHubName("Your eventHub Name")
.setSasKeyName("Enter the SAS key name")
.setSasKey("SAS Key details");
connStr.setTransportType(TransportType.AMQP_WEB_SOCKETS);
ProxySelector.setDefault(new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
LinkedList<Proxy> proxies = new LinkedList<>();
proxies.add(new Proxy(Proxy.Type.HTTP,
new InetSocketAddress("proxy information" ,port)));
return proxies;
}
@Override
public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
// trace and follow up on why proxy server is down
}
});