我已经看到在Spring AMQP中我们使用了folliwing结构:
String response = (String) template.convertSendAndReceive("query-example-2",message);
要获得回复,用户是否接收了消息。如何在没有spring框架的java中使用这个结构。我的制片人课程
public class EmitLogDirect {
private static final String EXCHANGE_NAME = "direct_logs";
public static void main(String[] argv) throws Exception {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
System.out.println("host: "+factory.getVirtualHost());
Connection connection = factory.newConnection();
Channel channel = connection.createChannel();
channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
String severity = getSeverity(argv);
String message = getMessage(argv);
channel.basicPublish(EXCHANGE_NAME, severity, null, message.getBytes("UTF-8"));
System.out.println(" [x] Sent '" + severity + "':'" + message + "'");
channel.close();
connection.close();
}