use of com.generallycloud.baseio.container.jms.client.MessageBrowser in project baseio by generallycloud.
the class TestBrowser method main.
public static void main(String[] args) throws Exception {
String queueName = "qName";
SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
ServerConfiguration configuration = new ServerConfiguration(8300);
SocketChannelContext context = new NioSocketChannelContext(configuration);
SocketChannelConnector connector = new SocketChannelConnector(context);
context.setIoEventHandleAdaptor(eventHandle);
context.setProtocolFactory(new ParamedProtobaseProtocolFactory());
context.addSessionEventListener(new LoggerSocketSEListener());
FixedSession session = new FixedSession(connector.connect());
session.login("admin", "admin100");
MessageBrowser browser = new DefaultMessageBrowser(session);
Message message = browser.browser(queueName);
System.out.println("message:" + message);
int size = browser.size();
System.out.println("size:" + size);
boolean isOnline = browser.isOnline(queueName);
System.out.println("isOnline:" + isOnline);
connector.close();
}
use of com.generallycloud.baseio.container.jms.client.MessageBrowser in project baseio by generallycloud.
the class BrowserExecutable method exec.
@Override
public CmdResponse exec(CommandContext context, HashMap<String, String> params) {
CmdResponse response = new CmdResponse();
MessageBrowser browser = getMessageBrowser(context);
if (browser == null) {
response.setResponse("请先登录!");
return response;
}
String messageId = params.get("-mid");
if (StringUtil.isNullOrBlank(messageId)) {
response.setResponse("参数不正确!\n" + "example:\n" + "browser -mid:mid");
return response;
}
try {
Message message = browser.browser(messageId);
if (message == null) {
response.setResponse("没有此id的消息!");
} else {
response.setResponse(message.toString());
}
} catch (Exception e) {
logger.debug(e);
}
return response;
}
use of com.generallycloud.baseio.container.jms.client.MessageBrowser in project baseio by generallycloud.
the class ConnectExecutable method exec.
@Override
public CmdResponse exec(CommandContext context, HashMap<String, String> params) {
CmdResponse response = new CmdResponse();
SocketChannelConnector connector = getClientConnector(context);
if (connector != null) {
response.setResponse("已登录。");
return response;
}
String username = params.get("-un");
String password = params.get("-p");
String host = params.get("-host");
String port = params.get("-port");
if (StringUtil.isNullOrBlank(username) || StringUtil.isNullOrBlank(password) || StringUtil.isNullOrBlank(host) || StringUtil.isNullOrBlank(port)) {
response.setResponse("参数不正确!\n" + "example:\n" + "connect -host:localhost -port:8300 -un:admin -p:admin100");
return response;
}
try {
NioSocketChannelContext baseContext = new NioSocketChannelContext(new ServerConfiguration(Integer.parseInt(port)));
connector = new SocketChannelConnector(baseContext);
SimpleIoEventHandle eventHandle = new SimpleIoEventHandle();
baseContext.setIoEventHandleAdaptor(eventHandle);
baseContext.addSessionEventListener(new LoggerSocketSEListener());
FixedSession session = new FixedSession(connector.connect());
// FIXME denglu cuowu
session.login(username, password);
MessageBrowser browser = new DefaultMessageBrowser(session);
response.setResponse("连接成功!");
setClientConnector(context, connector);
setMessageBrowser(context, browser);
} catch (Exception e) {
setClientConnector(context, null);
setMessageBrowser(context, null);
response.setResponse(e.getMessage());
// debug
logger.debug(e);
}
return response;
}
use of com.generallycloud.baseio.container.jms.client.MessageBrowser in project baseio by generallycloud.
the class MessageSizeExecutable method exec.
@Override
public CmdResponse exec(CommandContext context, HashMap<String, String> params) {
CmdResponse response = new CmdResponse();
MessageBrowser browser = getMessageBrowser(context);
if (browser == null) {
response.setResponse("请先登录!");
return response;
}
try {
int size = browser.size();
response.setResponse(String.valueOf(size));
} catch (Exception e) {
response.setResponse(e.getMessage());
logger.debug(e);
}
return response;
}
Aggregations