我想通过java在IBM MQ Lite中推送一条消息,因为我编写了一个代码: 在那里我使用IBM MQ Lite社区建议的AQMP协议。我想尝试使用ftp协议做同样的事情,我想知道天气是否有效,如果它工作需要在我的代码中进行哪些更改。
这是我的代码:
import com.ibm.mqlight.api.ClientOptions;
import com.ibm.mqlight.api.Delivery;
import com.ibm.mqlight.api.DestinationAdapter;
import com.ibm.mqlight.api.NonBlockingClient;
import com.ibm.mqlight.api.NonBlockingClientAdapter;
import com.ibm.mqlight.api.StringDelivery;
public class SendReceive2
{
public static void main(String[] cmdline)
{
ClientOptions clientOpts = ClientOptions.builder().setCredentials("ad", "jms123").build();
NonBlockingClient.create("ftp://localhost", clientOpts, new NonBlockingClientAdapter<Void>()
{
public void onStarted(NonBlockingClient client, Void context)
{
client.subscribe("JmsQueue", new DestinationAdapter<Void>()
{
public void onMessage(NonBlockingClient client, Void context, Delivery delivery)
{
if (delivery.getType() == Delivery.Type.STRING)
System.out.println(((StringDelivery)delivery).getData());
}
}, null, null);
}
}, null);
NonBlockingClient.create("ftp://localhost", clientOpts, new NonBlockingClientAdapter<Void>()
{
public void onStarted(NonBlockingClient client, Void context)
{
client.send("JmsQueue", "Jms Queue is Formed!", null);
}
}, null);
}//main
}//class