當前位置: 首頁>>代碼示例>>Java>>正文


Java BytesMessage.setJMSDeliveryMode方法代碼示例

本文整理匯總了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();
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:26,代碼來源:JMSMessageGroupsTest.java

示例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);
}
 
開發者ID:espertechinc,項目名稱:esper,代碼行數:69,代碼來源:ServerShellClientMain.java


注:本文中的javax.jms.BytesMessage.setJMSDeliveryMode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。