camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/6] camel git commit: Initial stub of PostgreSQL Async notifications component.
Date Tue, 23 Dec 2014 11:52:48 GMT
Initial stub of PostgreSQL Async notifications component.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7ce44a69
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7ce44a69
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7ce44a69

Branch: refs/heads/master
Commit: 7ce44a69897ad13316027206e277a2c29b7a6f39
Parents: bf4ddfe
Author: Deven Phillips <deven.phillips@gmail.com>
Authored: Thu Sep 4 09:13:55 2014 -0400
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Dec 23 12:26:59 2014 +0100

----------------------------------------------------------------------
 components/camel-pgasync/ReadMe.txt             |  18 ++++
 components/camel-pgasync/pom.xml                | 100 +++++++++++++++++++
 .../apache/camel/pgasync/PGAsyncComponent.java  |  18 ++++
 .../apache/camel/pgasync/PGAsyncConsumer.java   |  39 ++++++++
 .../apache/camel/pgasync/PGAsyncEndpoint.java   |  35 +++++++
 .../apache/camel/pgasync/PGAsyncProducer.java   |  24 +++++
 .../services/org/apache/camel/component/pgasync |   1 +
 .../org/apache/camel/PGAsyncComponentTest.java  |  28 ++++++
 .../src/test/resources/log4j.properties         |  14 +++
 9 files changed, 277 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7ce44a69/components/camel-pgasync/ReadMe.txt
----------------------------------------------------------------------
diff --git a/components/camel-pgasync/ReadMe.txt b/components/camel-pgasync/ReadMe.txt
new file mode 100644
index 0000000..8a79b62
--- /dev/null
+++ b/components/camel-pgasync/ReadMe.txt
@@ -0,0 +1,18 @@
+Camel PostgreSQL Async Notifications Component Project
+======================================================
+
+This component implements an Endpoint which can both
+produce and consume async notifications for PostgreSQL
+>= 9.2.
+
+
+==Building==
+To build this project use
+
+    mvn install
+
+==References==
+For more help see the Apache Camel documentation:
+
+    http://camel.apache.org/writing-components.html
+    

http://git-wip-us.apache.org/repos/asf/camel/blob/7ce44a69/components/camel-pgasync/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-pgasync/pom.xml b/components/camel-pgasync/pom.xml
new file mode 100644
index 0000000..631221b
--- /dev/null
+++ b/components/camel-pgasync/pom.xml
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <artifactId>components</artifactId>
+    <groupId>org.apache.camel</groupId>
+    <version>2.14-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>camel-pgasync</artifactId>
+  <packaging>bundle</packaging>
+  <name>Camel :: PgAsync</name>
+  <description>A component which can receive and send PostgreSQL Async notifications</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+    <camel.osgi.export.pkg>org.apache.camel.component.pgasync.*</camel.osgi.export.pkg>
+    <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=pgasync</camel.osgi.export.service>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-core</artifactId>
+      <version>2.13.2</version>
+    </dependency>
+
+    <!-- logging -->
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>1.7.7</version>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>1.7.7</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+      <version>1.2.17</version>
+      <scope>test</scope>
+    </dependency>
+
+    <!-- testing -->
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-test</artifactId>
+      <version>2.13.2</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <defaultGoal>install</defaultGoal>
+
+    <plugins>
+      
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>2.5.1</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.6</version>
+        <configuration>
+          <encoding>UTF-8</encoding>
+        </configuration>
+      </plugin>
+
+      <!-- to generate the MANIFEST-FILE of the bundle -->
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>2.3.7</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Bundle-SymbolicName>org.apache.camel.camel-pgasync</Bundle-SymbolicName>
+            <Export-Service>org.apache.camel.spi.ComponentResolver;component=pgasync</Export-Service>
+          </instructions>
+        </configuration>
+      </plugin>
+
+    </plugins>
+  </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/camel/blob/7ce44a69/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncComponent.java
b/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncComponent.java
new file mode 100644
index 0000000..2066ad8
--- /dev/null
+++ b/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncComponent.java
@@ -0,0 +1,18 @@
+package org.apache.camel.pgasync;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * Represents the component that manages {@link PGAsyncEndpoint}.
+ */
+public class PGAsyncComponent extends DefaultComponent {
+
+    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
+        Endpoint endpoint = new PGAsyncEndpoint(uri, this);
+        setProperties(endpoint, parameters);
+        return endpoint;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ce44a69/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncConsumer.java
b/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncConsumer.java
new file mode 100644
index 0000000..2f1bc9d
--- /dev/null
+++ b/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncConsumer.java
@@ -0,0 +1,39 @@
+package org.apache.camel.pgasync;
+
+import java.util.Date;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.ScheduledPollConsumer;
+
+/**
+ * The pgasync consumer.
+ */
+public class PGAsyncConsumer extends ScheduledPollConsumer {
+    private final PGAsyncEndpoint endpoint;
+
+    public PGAsyncConsumer(PGAsyncEndpoint endpoint, Processor processor) {
+        super(endpoint, processor);
+        this.endpoint = endpoint;
+    }
+
+    @Override
+    protected int poll() throws Exception {
+        Exchange exchange = endpoint.createExchange();
+
+        // create a message body
+        Date now = new Date();
+        exchange.getIn().setBody("Hello World! The time is " + now);
+
+        try {
+            // send message to next processor in the route
+            getProcessor().process(exchange);
+            return 1; // number of messages polled
+        } finally {
+            // log exception if an exception occurred and was not handled
+            if (exchange.getException() != null) {
+                getExceptionHandler().handleException("Error processing exchange", exchange,
exchange.getException());
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ce44a69/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncEndpoint.java
b/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncEndpoint.java
new file mode 100644
index 0000000..e164e05
--- /dev/null
+++ b/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncEndpoint.java
@@ -0,0 +1,35 @@
+package org.apache.camel.pgasync;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+
+/**
+ * Represents a pgasync endpoint.
+ */
+public class PGAsyncEndpoint extends DefaultEndpoint {
+
+    public PGAsyncEndpoint() {
+    }
+
+    public PGAsyncEndpoint(String uri, PGAsyncComponent component) {
+        super(uri, component);
+    }
+
+    public PGAsyncEndpoint(String endpointUri) {
+        super(endpointUri);
+    }
+
+    public Producer createProducer() throws Exception {
+        return new PGAsyncProducer(this);
+    }
+
+    public Consumer createConsumer(Processor processor) throws Exception {
+        return new PGAsyncConsumer(this, processor);
+    }
+
+    public boolean isSingleton() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ce44a69/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncProducer.java
b/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncProducer.java
new file mode 100644
index 0000000..61d51aa6
--- /dev/null
+++ b/components/camel-pgasync/src/main/java/org/apache/camel/pgasync/PGAsyncProducer.java
@@ -0,0 +1,24 @@
+package org.apache.camel.pgasync;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The pgasync producer.
+ */
+public class PGAsyncProducer extends DefaultProducer {
+    private static final Logger LOG = LoggerFactory.getLogger(PGAsyncProducer.class);
+    private PGAsyncEndpoint endpoint;
+
+    public PGAsyncProducer(PGAsyncEndpoint endpoint) {
+        super(endpoint);
+        this.endpoint = endpoint;
+    }
+
+    public void process(Exchange exchange) throws Exception {
+        System.out.println(exchange.getIn().getBody());    
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ce44a69/components/camel-pgasync/src/main/resources/META-INF/services/org/apache/camel/component/pgasync
----------------------------------------------------------------------
diff --git a/components/camel-pgasync/src/main/resources/META-INF/services/org/apache/camel/component/pgasync
b/components/camel-pgasync/src/main/resources/META-INF/services/org/apache/camel/component/pgasync
new file mode 100644
index 0000000..9020f10
--- /dev/null
+++ b/components/camel-pgasync/src/main/resources/META-INF/services/org/apache/camel/component/pgasync
@@ -0,0 +1 @@
+class=org.apache.camel.PGAsyncComponent

http://git-wip-us.apache.org/repos/asf/camel/blob/7ce44a69/components/camel-pgasync/src/test/java/org/apache/camel/PGAsyncComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-pgasync/src/test/java/org/apache/camel/PGAsyncComponentTest.java
b/components/camel-pgasync/src/test/java/org/apache/camel/PGAsyncComponentTest.java
new file mode 100644
index 0000000..68966d2
--- /dev/null
+++ b/components/camel-pgasync/src/test/java/org/apache/camel/PGAsyncComponentTest.java
@@ -0,0 +1,28 @@
+package org.apache.camel;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class PGAsyncComponentTest extends CamelTestSupport {
+
+    @Test
+    public void testpgasync() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMinimumMessageCount(1);       
+        
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            public void configure() {
+                from("pgasync://foo")
+                  .to("pgasync://bar")
+                  .to("mock:result");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/7ce44a69/components/camel-pgasync/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-pgasync/src/test/resources/log4j.properties b/components/camel-pgasync/src/test/resources/log4j.properties
new file mode 100644
index 0000000..3b1bd38
--- /dev/null
+++ b/components/camel-pgasync/src/test/resources/log4j.properties
@@ -0,0 +1,14 @@
+#
+# The logging properties used
+#
+log4j.rootLogger=INFO, out
+
+# uncomment the following line to turn on Camel debugging
+#log4j.logger.org.apache.camel=DEBUG
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+


Mime
View raw message