本文整理汇总了Java中com.solacesystems.jcsmp.BytesXMLMessage类的典型用法代码示例。如果您正苦于以下问题:Java BytesXMLMessage类的具体用法?Java BytesXMLMessage怎么用?Java BytesXMLMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BytesXMLMessage类属于com.solacesystems.jcsmp包,在下文中一共展示了BytesXMLMessage类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onReceive
import com.solacesystems.jcsmp.BytesXMLMessage; //导入依赖的package包/类
public void onReceive(BytesXMLMessage message) {
if (verbose.equals("verbose")) {
System.out.println("Received SMF (udp size: " + message.getAttachmentContentLength() + ")" );
}
// Processing in callback not recommended. For clarity, it is implemented this way for simplicity.
// Pass through msg content to UDP stream
DatagramPacket packet = new DatagramPacket(message.getAttachmentByteBuffer().array(),
message.getAttachmentContentLength(), address, port);
// Decapsulated and send to UDP
try {
dsocket.send(packet);
} catch (Exception ex) {
System.err.println("Encountered an Exception... " + ex.getMessage());
}
}
示例2: onReceive
import com.solacesystems.jcsmp.BytesXMLMessage; //导入依赖的package包/类
@Override
public void onReceive(BytesXMLMessage receivedMessage) {
numMessagesReceived.incrementAndGet();
if (receivedMessage instanceof TextMessage) {
lastReceivedMessage = (TextMessage) receivedMessage;
logger.info("Received message : " + lastReceivedMessage.getText());
} else {
logger.error("Received message that was not a TextMessage: " + receivedMessage.dump());
}
}
示例3: onReceive
import com.solacesystems.jcsmp.BytesXMLMessage; //导入依赖的package包/类
@Override
public void onReceive(BytesXMLMessage msg) {
if (msg instanceof TextMessage) {
System.out.printf("TextMessage received: '%s'%n", ((TextMessage) msg).getText());
} else {
System.out.println("Message received.");
}
System.out.printf("Message Dump:%n%s%n", msg.dump());
msg.ackMessage();
latch.countDown(); // unblock main thread
}
示例4: run
import com.solacesystems.jcsmp.BytesXMLMessage; //导入依赖的package包/类
public void run(String... args) throws JCSMPException, InterruptedException {
System.out.println("Input initializing...");
byte[] buffer = new byte[1500]; // Output from ffmpeg will not exceed 1500.
byte[] data;
DatagramPacket packet;
// Create a JCSMP Session
final JCSMPProperties properties = new JCSMPProperties();
properties.setProperty(JCSMPProperties.HOST, args[0]); // msg-backbone ip:port
properties.setProperty(JCSMPProperties.VPN_NAME, args[1]); // message-vpn
properties.setProperty(JCSMPProperties.USERNAME, args[2]); // client-username (assumes no password)
String t = args[3];
Topic topic = JCSMPFactory.onlyInstance().createTopic(t); // topic to publish the smf encapsulated udp stream to
String mode = args[4]; // direct or persistent
int port = Integer.parseInt(args[5]); // port to receive the udp stream
String verbose = args[6]; // verbose mode
session = JCSMPFactory.onlyInstance().createSession(properties);
session.connect();
XMLMessageProducer prod = session.getMessageProducer(new PubCallback());
// Publish-only session is now hooked up and running!
System.out.println("Connected.");
System.out.println("Control-C to exit");
try {
DatagramSocket dsocket = new DatagramSocket(port);
while (true) {
// Create a new DatagramPacket each time
packet = new DatagramPacket(buffer, buffer.length);
// Read data off socket
dsocket.receive(packet);
data = new byte[packet.getLength()];
System.arraycopy(packet.getData(), packet.getOffset(), data, 0, packet.getLength());
// Create SMF message and encapsulate
BytesXMLMessage msg = JCSMPFactory.onlyInstance().createMessage(BytesXMLMessage.class);
msg.writeAttachment(data);
if (mode.equals("persistent")) {
msg.setDeliveryMode(DeliveryMode.PERSISTENT);
} else {
// Everything else, even if wrong spelling, just default to direct.
msg.setDeliveryMode(DeliveryMode.DIRECT);
}
// Send message
prod.send(msg, topic);
if (verbose.equals("verbose"))
System.out.println("Sent SMF (udp size:" + packet.getLength() + ")" );
}
} catch (Exception ex) {
System.err.println("Encountered an Exception... " + ex.getMessage());
}
}
示例5: onReceive
import com.solacesystems.jcsmp.BytesXMLMessage; //导入依赖的package包/类
@Override
public void onReceive(BytesXMLMessage response) {
// Check if application will understand the message. Look for a
// message type property with value "DEMO_RESPONSE"
SDTMap propertiesMap = response.getProperties();
if (propertiesMap == null
|| !propertiesMap.containsKey(MSG_TYPE_HEADER)
|| !(response instanceof TextMessage)) {
log.warn("Receive message not matching expected format.");
log.warn(response.dump());
response.ackMessage();
return;
}
String msgType = null;
try {
msgType = propertiesMap.getString(MSG_TYPE_HEADER);
} catch (SDTException e1) {
log.warn("Error retrieving message header.", e1);
log.warn(response.dump());
response.ackMessage();
return;
}
if (!msgType.equals(RESPONSE_MSG_TYPE)) {
log.warn("Message Type not expected. Received: " + msgType);
log.warn(response.dump());
response.ackMessage();
return;
}
try {
WorkResponse workResponse = (WorkResponse) new ObjectMapper()
.readValue(((TextMessage) response).getText(),
WorkResponse.class);
long timeRecvd = System.nanoTime();
jobStatus.newResponseReceived(workResponse, timeRecvd);
// Track the response globally too.
globalStats.incResponseReceived();
} catch (IOException e) {
log.error("Unable to parse message body.", e);
log.error(response.dump());
}
response.ackMessage();
}