人人社区!

azure service bus implements messagehandler Java example

2023-04-28 71 1



import com.microsoft.azure.servicebus.*;
import java.util.concurrent.*;

public class App {

static final String ServiceBusConnectionString = "";
static final String QueueName = "";
static QueueClient queueClient;

public static void main(String[] args) throws Exception {
queueClient = new QueueClient(new ConnectionStringBuilder(ServiceBusConnectionString, QueueName),
ReceiveMode.RECEIVEANDDELETE);

registerMessageHandlerOnClient();

System.out.println("Press any key to exit.");
System.in.read();
queueClient.close();
}

static void registerMessageHandlerOnClient() throws Exception{
queueClient.registerMessageHandler(
// callback when Message is received
new IMessageHandler() {
@Override
public CompletableFuture onMessageAsync( IMessage message) {
System.out.println(message.getMessageId());
return CompletableFuture.completedFuture(null);
}

@Override public void notifyException(Throwable throwable, ExceptionPhase exceptionPhase) {
System.out.println(exceptionPhase + "-" + throwable.getMessage());
}
},
// callback when call fails
new IMessageHandlerExceptionAction() {
@Override
public CompletableFuture onExceptionAsync(Throwable throwable, ExceptionPhase exceptionPhase) {
System.out.println(exceptionPhase + "-" + throwable.getMessage());
return CompletableFuture.completedFuture(null);
}
}
);
}
}

加拿大买卖房子找Tony Zhu

地址:8300 Woodbine Ave #100T, Markham, ON

手机:416-618-1235 电话:905-909-0101

点击看房源
顶部