我创建了一个使用Azure Service Bus java SDK
发送/接收主题消息的java应用程序,如果我将它作为Java应用程序运行,它的工作正常。
我将应用程序jar
以及所有依赖项jar导出到{ColdFusionInstallation}\cfusion\lib
并重新启动了ColdFusion Application Server。
我能够在转储时创建类对象并查看它们的定义,但是当我尝试从类中调用任何特定方法时,它将永远占用。
<cfset objSender = createObject( "java", "com.test.Sender" ).init()>
<cfset objSender.sendAsync( JavaCast( "string", "cftest" ) )>
Sender.java
package com.test;
import java.util.concurrent.CompletableFuture;
import org.apache.log4j.Logger;
import com.microsoft.azure.servicebus.IMessage;
import com.microsoft.azure.servicebus.ITopicClient;
import com.microsoft.azure.servicebus.Message;
import com.microsoft.azure.servicebus.TopicClient;
import com.microsoft.azure.servicebus.primitives.ConnectionStringBuilder;
import com.microsoft.azure.servicebus.primitives.ServiceBusException;
public class Sender {
private final String namespaceConnectionString = "Endpoint=sb.......";
private final String namespaceTopicName = "test";
private static Logger logger = Logger.getRootLogger();
public CompletableFuture<Void> sendAsync( String message ) {
// Get client
ITopicClient topicClient = this.createTopicClient( this.namespaceTopicName );
// Send Async
CompletableFuture<Void> future = topicClient.sendAsync(
new Message( message )
).thenRunAsync( () -> {
try {
topicClient.close();
} catch (Exception e) {
logger.info( "Unable to close topic client!" );
}
} );
return future;
}
private ITopicClient createTopicClient( String topicName ) throws RuntimeException {
// Create client for topic
ITopicClient topicClient = null;
try {
// Create
topicClient = new TopicClient(
new ConnectionStringBuilder( this.namespaceConnectionString, topicName )
);
} catch ( InterruptedException | ServiceBusException e ) {
logger.info( "Unable to client for topic: " + topicName );
throw new RuntimeException( "Unable to create client for topic: " + topicName );
}
return topicClient;
}
}
我不确定是什么问题,因为它在直接运行时起作用。
任何建议都非常感谢!