List of usage examples for javax.jms TextMessage setText
void setText(String string) throws JMSException;
From source file:org.apache.activemq.usecases.DurableSubscriptionHangTestCase.java
private void sendRandomMessage(TopicSession session, MessageProducer producer) throws JMSException { TextMessage textMessage = session.createTextMessage(); textMessage.setText(RandomStringUtils.random(500, "abcdefghijklmnopqrstuvwxyz")); producer.send(textMessage);/*from w w w.ja va2 s .com*/ }
From source file:org.btc4j.jms.BtcDaemonCaller.java
public String sendReceive(final String destination, final String payload) { return jmsTemplate.execute(new SessionCallback<String>() { @Override/*from www .j a v a 2 s . c om*/ public String doInJms(Session session) throws JMSException { final TemporaryQueue replyQueue = session.createTemporaryQueue(); jmsTemplate.send(destination, new MessageCreator() { @Override public Message createMessage(Session session) throws JMSException { TextMessage message = session.createTextMessage(); message.setJMSReplyTo(replyQueue); message.setText(payload); message.setStringProperty("btcapi:account", account); message.setStringProperty("btcapi:password", password); return message; } }); return String.valueOf(jmsTemplate.receiveAndConvert(replyQueue)); } }); }
From source file:pl.psnc.synat.wrdz.zu.certificate.CertificateChecker.java
/** * Notifies the system monitor that the given user has a certificate that's beyond the expiration threshold. * // www .j ava 2 s . co m * @param username * name of the user with the (nearly) expired certificate */ private void notifyExpirationCheckFail(String username) { QueueConnection connection = null; try { connection = queueConnectionFactory.createQueueConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); TextMessage message = session.createTextMessage(); message.setText(username); session.createProducer(certificateQueue).send(message); } catch (JMSException e) { logger.error("Sending message to the JMS queue failed", e); } finally { if (connection != null) { try { connection.close(); } catch (JMSException e) { logger.error("Error while closing a connection.", e); } } } }
From source file:net.blogracy.services.SeedService.java
@Override public void onMessage(Message request) { try {/*from www . j av a 2 s .c o m*/ String text = ((TextMessage) request).getText(); Logger.info("seed service:" + text + ";"); JSONObject entry = new JSONObject(text); try { File file = new File(entry.getString("file")); Torrent torrent = plugin.getTorrentManager().createFromDataFile(file, new URL("udp://tracker.openbittorrent.com:80")); torrent.setComplete(file.getParentFile()); String name = Base32.encode(torrent.getHash()); int index = file.getName().lastIndexOf('.'); if (0 < index && index <= file.getName().length() - 2) { name = name + file.getName().substring(index); } Download download = plugin.getDownloadManager().addDownload(torrent, null, // torrentFile, file.getParentFile()); if (download != null) download.renameDownload(name); entry.put("uri", torrent.getMagnetURI().toExternalForm()); if (request.getJMSReplyTo() != null) { TextMessage response = session.createTextMessage(); response.setText(entry.toString()); response.setJMSCorrelationID(request.getJMSCorrelationID()); producer.send(request.getJMSReplyTo(), response); } } catch (MalformedURLException e) { Logger.error("Malformed URL error: seed service " + text); } catch (TorrentException e) { Logger.error("Torrent error: seed service: " + text); e.printStackTrace(); } catch (DownloadException e) { Logger.error("Download error: seed service: " + text); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } catch (JMSException e) { Logger.error("JMS error: seed service"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.easybatch.jms.JmsIntegrationTest.java
@Test public void testJmsSupport() throws Exception { Context jndiContext = getJndiContext(); QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) jndiContext .lookup("QueueConnectionFactory"); Queue queue = (Queue) jndiContext.lookup("q"); QueueConnection queueConnection = queueConnectionFactory.createQueueConnection(); QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); QueueSender queueSender = queueSession.createSender(queue); queueConnection.start();// www. j a v a 2 s . co m //send a regular message to the queue TextMessage message = queueSession.createTextMessage(); message.setText(MESSAGE_TEXT); queueSender.send(message); //send a poison record to the queue queueSender.send(new JmsPoisonMessage()); Job job = aNewJob().reader(new JmsQueueRecordReader(queueConnectionFactory, queue)) .filter(new JmsPoisonRecordFilter()).processor(new RecordCollector()) .jobListener(new JmsQueueSessionListener(queueSession)) .jobListener(new JmsQueueConnectionListener(queueConnection)).build(); JobReport jobReport = JobExecutor.execute(job); assertThat(jobReport).isNotNull(); assertThat(jobReport.getParameters().getDataSource()).isEqualTo(EXPECTED_DATA_SOURCE_NAME); assertThat(jobReport.getMetrics().getTotalCount()).isEqualTo(2); assertThat(jobReport.getMetrics().getFilteredCount()).isEqualTo(1); assertThat(jobReport.getMetrics().getSuccessCount()).isEqualTo(1); List<JmsRecord> records = (List<JmsRecord>) jobReport.getResult(); assertThat(records).isNotNull().isNotEmpty().hasSize(1); JmsRecord jmsRecord = records.get(0); Header header = jmsRecord.getHeader(); assertThat(header).isNotNull(); assertThat(header.getNumber()).isEqualTo(1); assertThat(header.getSource()).isEqualTo(EXPECTED_DATA_SOURCE_NAME); Message payload = jmsRecord.getPayload(); assertThat(payload).isNotNull().isInstanceOf(TextMessage.class); TextMessage textMessage = (TextMessage) payload; assertThat(textMessage.getText()).isNotNull().isEqualTo(MESSAGE_TEXT); }
From source file:net.blogracy.controller.DistributedHashTable.java
public void store(final String id, final String uri, final String version) { try {/*from www .ja v a 2s.c o m*/ JSONObject record = new JSONObject(); record.put("id", id); record.put("uri", uri); record.put("version", version); // put "magic" public-key; e.g. // RSA.modulus(n).exponent(e) // record.put("signature", user); // TODO KeyPair keyPair = Configurations.getUserConfig().getUserKeyPair(); String value = JsonWebSignature.sign(record.toString(), keyPair); JSONObject keyValue = new JSONObject(); keyValue.put("key", id); keyValue.put("value", value); TextMessage message = session.createTextMessage(); message.setText(keyValue.toString()); producer.send(storeQueue, message); putRecord(record); } catch (Exception e) { e.printStackTrace(); } }
From source file:net.blogracy.controller.DistributedHashTable.java
public void lookup(final String id) { try {/*from w ww .j a v a 2s. co m*/ Destination tempDest = session.createTemporaryQueue(); MessageConsumer responseConsumer = session.createConsumer(tempDest); responseConsumer.setMessageListener(new MessageListener() { @Override public void onMessage(Message response) { try { String msgText = ((TextMessage) response).getText(); JSONObject keyValue = new JSONObject(msgText); String value = keyValue.getString("value"); PublicKey signerKey = JsonWebSignature.getSignerKey(value); JSONObject record = new JSONObject(JsonWebSignature.verify(value, signerKey)); JSONObject currentRecord = getRecord(id); if (currentRecord == null || currentRecord.getString("version").compareTo(record.getString("version")) < 0) { putRecord(record); String uri = record.getString("uri"); FileSharing.getSingleton().download(uri); } } catch (Exception e) { e.printStackTrace(); } } }); JSONObject record = new JSONObject(); record.put("id", id); TextMessage message = session.createTextMessage(); message.setText(record.toString()); message.setJMSReplyTo(tempDest); producer.send(lookupQueue, message); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.apache.qpid.disttest.client.MessageProvider.java
protected Message createTextMessage(Session ssn, final CreateProducerCommand command) throws JMSException { String payload = getMessagePayload(command); TextMessage msg = null; synchronized (ssn) { msg = ssn.createTextMessage();//from ww w . j a va2s. co m } msg.setText(payload); return msg; }
From source file:TopicRequestor.java
/** Create JMS client for publishing and subscribing to messages. */ private void start(String broker, String username, String password) { // Create a connection. try {/*from w ww .ja va2 s. co m*/ javax.jms.TopicConnectionFactory factory; factory = new ActiveMQConnectionFactory(username, password, broker); connect = factory.createTopicConnection(username, password); session = connect.createTopicSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE); } catch (javax.jms.JMSException jmse) { System.err.println("error: Cannot connect to Broker - " + broker); jmse.printStackTrace(); System.exit(1); } // Create Topic for all requests. TopicRequestor will be created // as needed. javax.jms.Topic topic = null; try { topic = session.createTopic(APP_TOPIC); // Now that all setup is complete, start the Connection connect.start(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } try { // Read all standard input and send it as a message. java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); System.out.println("\nRequestor application:\n" + "============================\n" + "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n" + "The application uses a TopicRequestor to on the " + APP_TOPIC + " topic." + "The Replier application gets the message, and transforms it." + "The Requestor application displays the result.\n\n" + "Type some mixed case text, and then press Enter to make a request.\n"); while (true) { String s = stdin.readLine(); if (s == null) exit(); else if (s.length() > 0) { javax.jms.TextMessage msg = session.createTextMessage(); msg.setText(username + ": " + s); // Instead of publishing, we will use a TopicRequestor. javax.jms.TopicRequestor requestor = new javax.jms.TopicRequestor(session, topic); javax.jms.Message response = requestor.request(msg); // The message should be a TextMessage. Just report it. javax.jms.TextMessage textMessage = (javax.jms.TextMessage) response; System.out.println("[Reply] " + textMessage.getText()); } } } catch (java.io.IOException ioe) { ioe.printStackTrace(); } catch (javax.jms.JMSException jmse) { jmse.printStackTrace(); } }
From source file:org.apache.flume.source.jms.TestIntegrationActiveMQ.java
private void putQueue(List<String> events) throws Exception { ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKER_BIND_URL); Connection connection = factory.createConnection(); connection.start();/*ww w . j av a2 s .co m*/ Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); Destination destination = session.createQueue(DESTINATION_NAME); MessageProducer producer = session.createProducer(destination); for (String event : events) { TextMessage message = session.createTextMessage(); message.setText(event); producer.send(message); } session.commit(); session.close(); connection.close(); }