本文整理汇总了Java中javax.jms.BytesMessage.setJMSDeliveryMode方法的典型用法代码示例。如果您正苦于以下问题:Java BytesMessage.setJMSDeliveryMode方法的具体用法?Java BytesMessage.setJMSDeliveryMode怎么用?Java BytesMessage.setJMSDeliveryMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jms.BytesMessage
的用法示例。
在下文中一共展示了BytesMessage.setJMSDeliveryMode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessagesToBroker
import javax.jms.BytesMessage; //导入方法依赖的package包/类
protected void sendMessagesToBroker(Connection connection, int count, AtomicInteger sequence) throws Exception {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue(getQueueName());
MessageProducer producer = session.createProducer(queue);
byte[] buffer = new byte[MESSAGE_SIZE];
for (count = 0; count < MESSAGE_SIZE; count++) {
String s = String.valueOf(count % 10);
Character c = s.charAt(0);
int value = c.charValue();
buffer[count] = (byte) value;
}
LOG.debug("Sending {} messages to destination: {}", MESSAGE_COUNT, queue);
for (int i = 1; i <= MESSAGE_COUNT; i++) {
BytesMessage message = session.createBytesMessage();
message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
message.setStringProperty("JMSXGroupID", JMSX_GROUP_ID);
message.setIntProperty("JMSXGroupSeq", sequence.incrementAndGet());
message.writeBytes(buffer);
producer.send(message);
}
session.close();
}
示例2: ServerShellClientMain
import javax.jms.BytesMessage; //导入方法依赖的package包/类
public ServerShellClientMain() throws Exception {
log.info("Loading properties");
Properties properties = new Properties();
InputStream propertiesIS = ServerShellClientMain.class.getClassLoader().getResourceAsStream(ServerShellConstants.CONFIG_FILENAME);
if (propertiesIS == null) {
throw new RuntimeException("Properties file '" + ServerShellConstants.CONFIG_FILENAME + "' not found in classpath");
}
properties.load(propertiesIS);
// Attached via JMX to running server
log.info("Attach to server via JMX");
JMXServiceURL url = new JMXServiceURL(properties.getProperty(ServerShellConstants.MGMT_SERVICE_URL));
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();
ObjectName mBeanName = new ObjectName(ServerShellConstants.MGMT_MBEAN_NAME);
EPServiceProviderJMXMBean proxy = (EPServiceProviderJMXMBean) MBeanServerInvocationHandler.newProxyInstance(
mbsc, mBeanName, EPServiceProviderJMXMBean.class, true);
// Connect to JMS
log.info("Connecting to JMS server");
String factory = properties.getProperty(ServerShellConstants.JMS_CONTEXT_FACTORY);
String jmsurl = properties.getProperty(ServerShellConstants.JMS_PROVIDER_URL);
String connFactoryName = properties.getProperty(ServerShellConstants.JMS_CONNECTION_FACTORY_NAME);
String user = properties.getProperty(ServerShellConstants.JMS_USERNAME);
String password = properties.getProperty(ServerShellConstants.JMS_PASSWORD);
String destination = properties.getProperty(ServerShellConstants.JMS_INCOMING_DESTINATION);
boolean isTopic = Boolean.parseBoolean(properties.getProperty(ServerShellConstants.JMS_IS_TOPIC));
JMSContext jmsCtx = JMSContextFactory.createContext(factory, jmsurl, connFactoryName, user, password, destination, isTopic);
// Create statement via JMX
log.info("Creating a statement via Java Management Extensions (JMX) MBean Proxy");
proxy.createEPL("select * from SampleEvent where duration > 9.9", "filterStatement", new ClientSideUpdateListener());
// Get producer
jmsCtx.getConnection().start();
MessageProducer producer = jmsCtx.getSession().createProducer(jmsCtx.getDestination());
Random random = new Random();
String[] ipAddresses = {"127.0.1.0", "127.0.2.0", "127.0.3.0", "127.0.4.0"};
NumberFormat format = NumberFormat.getInstance();
// Send messages
for (int i = 0; i < 1000; i++) {
String ipAddress = ipAddresses[random.nextInt(ipAddresses.length)];
double duration = 10 * random.nextDouble();
String durationStr = format.format(duration);
String payload = ipAddress + "," + durationStr;
BytesMessage bytesMessage = jmsCtx.getSession().createBytesMessage();
bytesMessage.writeBytes(payload.getBytes());
bytesMessage.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
producer.send(bytesMessage);
if (i % 100 == 0) {
log.info("Sent " + i + " messages");
}
}
// Create statement via JMX
log.info("Destroing statement via Java Management Extensions (JMX) MBean Proxy");
proxy.destroy("filterStatement");
log.info("Shutting down JMS client connection");
jmsCtx.destroy();
log.info("Exiting");
System.exit(-1);
}