You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jb...@apache.org on 2017/03/09 19:45:24 UTC

[1/2] activemq-artemis git commit: ARTEMIS-1021 Improving CPP to produce a TextMessage using UTF-8

Repository: activemq-artemis
Updated Branches:
  refs/heads/master 101c6e686 -> d408c4634


ARTEMIS-1021 Improving CPP to produce a TextMessage using UTF-8


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/1ece044d
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/1ece044d
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/1ece044d

Branch: refs/heads/master
Commit: 1ece044dfccae9b472df1db1526b7c5090720df0
Parents: 101c6e6
Author: Clebert Suconic <cl...@apache.org>
Authored: Thu Mar 9 11:05:16 2017 -0500
Committer: Justin Bertram <jb...@apache.org>
Committed: Thu Mar 9 13:45:12 2017 -0600

----------------------------------------------------------------------
 examples/protocols/amqp/proton-cpp/pom.xml      |  5 ++
 .../amqp/proton-cpp/src/main/cpp/hello.cpp      | 30 +++++---
 .../artemis/jms/example/ProtonCPPExample.java   | 81 ++++++++------------
 3 files changed, 55 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/1ece044d/examples/protocols/amqp/proton-cpp/pom.xml
----------------------------------------------------------------------
diff --git a/examples/protocols/amqp/proton-cpp/pom.xml b/examples/protocols/amqp/proton-cpp/pom.xml
index 5034efc..76fc7bf 100644
--- a/examples/protocols/amqp/proton-cpp/pom.xml
+++ b/examples/protocols/amqp/proton-cpp/pom.xml
@@ -45,6 +45,11 @@ under the License.
          <groupId>org.apache.geronimo.specs</groupId>
          <artifactId>geronimo-jms_2.0_spec</artifactId>
       </dependency>
+      <dependency>
+         <groupId>org.apache.qpid</groupId>
+         <artifactId>qpid-jms-client</artifactId>
+         <version>${qpid.jms.version}</version>
+      </dependency>
    </dependencies>
 
    <build>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/1ece044d/examples/protocols/amqp/proton-cpp/src/main/cpp/hello.cpp
----------------------------------------------------------------------
diff --git a/examples/protocols/amqp/proton-cpp/src/main/cpp/hello.cpp b/examples/protocols/amqp/proton-cpp/src/main/cpp/hello.cpp
index 214d255..bfe18ff 100644
--- a/examples/protocols/amqp/proton-cpp/src/main/cpp/hello.cpp
+++ b/examples/protocols/amqp/proton-cpp/src/main/cpp/hello.cpp
@@ -33,7 +33,7 @@ using namespace qpid::messaging;
 
 int main(int argc, char** argv) {
     std::string broker = argc > 1 ? argv[1] : "localhost:61616";
-    std::string address = argc > 2 ? argv[2] : "jms.queue.exampleQueue";
+    std::string address = argc > 2 ? argv[2] : "exampleQueue";
 
     // Connection options documented at http://qpid.apache.org/releases/qpid-0.30/programming/book/connections.html#connection-options
     std::string connectionOptions = argc > 3 ? argv[3] : "{protocol:amqp1.0}";
@@ -49,20 +49,28 @@ int main(int argc, char** argv) {
          // Step 5. Create a sender
         Sender sender = session.createSender(address);
 
-         // Step 6. send a simple message
-        sender.send(Message("Hello world!"));
-
-         // Step 7. create a receiver
+        //create a receiver
         Receiver receiver = session.createReceiver(address);
 
-         // Step 8. receive the simple message
-        Message message = receiver.fetch(Duration::SECOND * 1);
-        std::cout << "Received a message with this following content \"" << message.getContent() << "\"" << std::endl;
 
-         // Step 9. acknowledge the message
-        session.acknowledge();
+        for (int i = 0; i < 10; i++) {
+            Message message;
+            message.getContentObject() = "Hello world!";
+
+            message.getContentObject().setEncoding("utf8");
+            message.setContentType("text/plain");
+
+            sender.send(message);
+
+            // receive the simple message
+            message = receiver.fetch(Duration::SECOND * 1);
+            std::cout << "Received a message with this following content \"" << message.getContent() << "\"" << std::endl;
+
+            // acknowledge the message
+            session.acknowledge();
+        }
 
-        // Step 10. close the connection
+        // close the connection
         connection.close();
         return 0;
     } catch(const std::exception& error) {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/1ece044d/examples/protocols/amqp/proton-cpp/src/main/java/org/apache/activemq/artemis/jms/example/ProtonCPPExample.java
----------------------------------------------------------------------
diff --git a/examples/protocols/amqp/proton-cpp/src/main/java/org/apache/activemq/artemis/jms/example/ProtonCPPExample.java b/examples/protocols/amqp/proton-cpp/src/main/java/org/apache/activemq/artemis/jms/example/ProtonCPPExample.java
index 0c389f4..961a56b 100644
--- a/examples/protocols/amqp/proton-cpp/src/main/java/org/apache/activemq/artemis/jms/example/ProtonCPPExample.java
+++ b/examples/protocols/amqp/proton-cpp/src/main/java/org/apache/activemq/artemis/jms/example/ProtonCPPExample.java
@@ -18,24 +18,19 @@ package org.apache.activemq.artemis.jms.example;
 
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
-import javax.jms.Message;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
 import javax.jms.Queue;
-import javax.jms.QueueConnection;
-import javax.jms.QueueRequestor;
-import javax.jms.QueueSession;
 import javax.jms.Session;
+import javax.jms.TextMessage;
 import javax.naming.InitialContext;
 
-import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
-import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper;
-import org.apache.activemq.artemis.api.core.management.ResourceNames;
+import org.apache.qpid.jms.JmsConnectionFactory;
 
 /**
  * This example demonstrates the use of ActiveMQ Artemis "pre-acknowledge" functionality where
  * messages are acknowledged before they are delivered to the consumer.
- *
+ * <p>
  * Please see the readme.html for more details.
  */
 public class ProtonCPPExample {
@@ -45,24 +40,26 @@ public class ProtonCPPExample {
 
       InitialContext initialContext = null;
       try {
-         // Step 1. Create an initial context to perform the JNDI lookup.
+         // Create an initial context to perform the JNDI lookup.
          initialContext = new InitialContext();
 
-         // Step 2. Perform the look-ups
-         Queue queue = (Queue) initialContext.lookup("queue/exampleQueue");
-
-         ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("ConnectionFactory");
+         // if you wanted to use Core JMS, use this line instead.
+         // ConnectionFactory cf = new ActiveMQConnectionFactory();
+         ConnectionFactory cf = new JmsConnectionFactory("amqp://localhost:61616");
 
-         // Step 3. Create a the JMS objects
+         // Create a the JMS objects
          connection = cf.createConnection();
 
          Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
 
+         // Perform the look-ups
+         Queue queue = session.createQueue("exampleQueue");
+
          MessageConsumer messageConsumer = session.createConsumer(queue);
 
          MessageProducer producerAnswer = session.createProducer(queue);
 
-         // Step 4. Start the connection
+         // Start the connection
          connection.start();
 
          System.out.println("On a shell script, execute the following:");
@@ -71,18 +68,25 @@ public class ProtonCPPExample {
 
          System.out.println("./hello");
 
-         // Step 5. Finally, receive the message
-         Message messageReceived = messageConsumer.receive(5000);
-
-         if (messageReceived == null) {
-            // We are not going to issue this as an error because
-            // we also use this example as part of our tests on artemis
-            // this is not considered an error, just that no messages arrived (i.e. hello wasn't called)
-         } else {
-            System.out.println("message received: " + messageReceived);
-
-            // Sending message back to client
-            producerAnswer.send(session.createTextMessage("HELLO from Apache ActiveMQ Artemis"));
+         for (int i = 0; i < 10; i++) {
+            try {
+               // Step 5. Finally, receive the message
+               TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);
+
+               if (messageReceived == null) {
+                  System.out.println("No messages");
+                  // We are not going to issue this as an error because
+                  // we also use this example as part of our tests on artemis
+                  // this is not considered an error, just that no messages arrived (i.e. hello wasn't called)
+               } else {
+                  System.out.println("message received: " + messageReceived.getText());
+
+                  // Sending message back to client
+                  producerAnswer.send(session.createTextMessage("HELLO from Apache ActiveMQ Artemis " + i + "!!"));
+               }
+            } catch (Throwable e) {
+               e.printStackTrace();
+            }
          }
       } finally {
          // Step 9. Be sure to close our resources!
@@ -94,27 +98,4 @@ public class ProtonCPPExample {
          }
       }
    }
-
-   // To do this we send a management message to get the message count.
-   // In real life you wouldn't create a new session every time you send a management message
-   private int getMessageCount(final Connection connection) throws Exception {
-      QueueSession session = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
-
-      Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management");
-
-      QueueRequestor requestor = new QueueRequestor(session, managementQueue);
-
-      connection.start();
-
-      Message m = session.createMessage();
-
-      JMSManagementHelper.putAttribute(m, ResourceNames.QUEUE + "exampleQueue", "messageCount");
-
-      Message response = requestor.request(m);
-
-      int messageCount = (Integer) JMSManagementHelper.getResult(response);
-
-      return messageCount;
-   }
-
 }


[2/2] activemq-artemis git commit: This closes #1076

Posted by jb...@apache.org.
This closes #1076


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/d408c463
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/d408c463
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/d408c463

Branch: refs/heads/master
Commit: d408c463406aba570c7c514df13b9390500cc89a
Parents: 101c6e6 1ece044
Author: Justin Bertram <jb...@apache.org>
Authored: Thu Mar 9 13:45:13 2017 -0600
Committer: Justin Bertram <jb...@apache.org>
Committed: Thu Mar 9 13:45:13 2017 -0600

----------------------------------------------------------------------
 examples/protocols/amqp/proton-cpp/pom.xml      |  5 ++
 .../amqp/proton-cpp/src/main/cpp/hello.cpp      | 30 +++++---
 .../artemis/jms/example/ProtonCPPExample.java   | 81 ++++++++------------
 3 files changed, 55 insertions(+), 61 deletions(-)
----------------------------------------------------------------------