Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion activemq-filters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<filters />
<filters/>
</configuration>
<executions>
<execution>
Expand Down
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<awaitility.version>4.2.0</awaitility.version>
<maven.antrun.plugin.version>3.1.0</maven.antrun.plugin.version>
<snakeyaml.version>2.0</snakeyaml.version>
<testcontainers.version>1.20.4</testcontainers.version>
<testcontainers.version>1.21.4</testcontainers.version>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change here? revert it this is not the scope in this PR

<lombok.version>1.18.42</lombok.version>
<!-- required for running tests on JDK11+ -->
<test.additional.args>--add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/jdk.internal.loader=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED
Expand Down Expand Up @@ -325,6 +325,18 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>pulsar</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
Expand Down
6 changes: 3 additions & 3 deletions pulsar-client-shaded/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<configuration>
<target>
<!-- shade the AsyncHttpClient ahc-default.properties files -->
<replace token="org.asynchttpclient." value="org.apache.pulsar.shade.org.asynchttpclient." file="${project.build.directory}/classes/org/asynchttpclient/config/ahc-default.properties" />
<replace token="org.asynchttpclient." value="org.apache.pulsar.shade.org.asynchttpclient." file="${project.build.directory}/classes/org/asynchttpclient/config/ahc-default.properties"/>
</target>
</configuration>
</execution>
Expand Down Expand Up @@ -480,8 +480,8 @@
</relocation>
</relocations>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.PluginXmlResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.PluginXmlResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Multi-Release>true</Multi-Release>
Expand Down
4 changes: 2 additions & 2 deletions pulsar-jms-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@
<configuration>
<target>
<echo>copy filters</echo>
<mkdir dir="${project.build.outputDirectory}/filters" />
<copy verbose="true" file="${basedir}/../pulsar-jms-filters/target/pulsar-jms-${project.version}-nar.nar" tofile="${project.build.outputDirectory}/filters/jms-filter.nar" />
<mkdir dir="${project.build.outputDirectory}/filters"/>
<copy verbose="true" file="${basedir}/../pulsar-jms-filters/target/pulsar-jms-${project.version}-nar.nar" tofile="${project.build.outputDirectory}/filters/jms-filter.nar"/>
</target>
</configuration>
</execution>
Expand Down
28 changes: 24 additions & 4 deletions pulsar-jms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${testcontainers.version}</version>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it.

<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -173,15 +180,28 @@
<configuration>
<target>
<echo>copy filters</echo>
<mkdir dir="${project.build.outputDirectory}/filters" />
<mkdir dir="${project.build.outputDirectory}/interceptors" />
<copy verbose="true" file="${basedir}/../pulsar-jms-filters/target/pulsar-jms-${project.version}-nar.nar" tofile="${project.build.outputDirectory}/filters/jms-filter.nar" />
<copy verbose="true" file="${basedir}/../pulsar-jms-filters/target/pulsar-jms-${project.version}-nar.nar" tofile="${project.build.outputDirectory}/interceptors/jms-filter.nar" />
<mkdir dir="${project.build.outputDirectory}/filters"/>
<mkdir dir="${project.build.outputDirectory}/interceptors"/>
<copy verbose="true" file="${basedir}/../pulsar-jms-filters/target/pulsar-jms-${project.version}-nar.nar" tofile="${project.build.outputDirectory}/filters/jms-filter.nar"/>
<copy verbose="true" file="${basedir}/../pulsar-jms-filters/target/pulsar-jms-${project.version}-nar.nar" tofile="${project.build.outputDirectory}/interceptors/jms-filter.nar"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it.

<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.example.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,17 @@ public void createSubscription(
String selector,
boolean fromBeginning)
throws JMSException {

PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination);
validateSelector(enableFilters, selector);
Map<String, String> properties = new HashMap<>();
if (enableFilters) {
properties.put("jms.filtering", "true");
properties.put("jms.selector", selector);
}
String topicName = factory.getPulsarTopicName(dest);
Utils.setContext(topicName);
try {
PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination);
validateSelector(enableFilters, selector);
Map<String, String> properties = new HashMap<>();
if (enableFilters) {
properties.put("jms.filtering", "true");
properties.put("jms.selector", selector);
}
String topicName = factory.getPulsarTopicName(dest);
Topics topics = factory.ensurePulsarAdmin().topics();
topics.createSubscription(
topicName,
Expand All @@ -344,20 +346,22 @@ public void createSubscription(
properties);
} catch (PulsarAdminException error) {
throw Utils.handleException(error);
} finally {
Utils.clearContext();
}
}

@Override
public void createQueue(Queue destination, int partitions, boolean enableFilters, String selector)
throws JMSException {
checkArgument(() -> partitions >= 0, "Invalid number of partitions " + partitions);
validateSelector(enableFilters, selector);
PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination);
String topicName = factory.getPulsarTopicName(dest);
Utils.setContext(topicName);
try {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why move try?

PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination);
checkArgument(() -> partitions >= 0, "Invalid number of partitions " + partitions);
validateSelector(enableFilters, selector);
checkDestination(
destination, d -> !dest.isVirtualDestination(), "Cannot create a VirtualDestination");

String topicName = factory.getPulsarTopicName(dest);
Topics topics = factory.ensurePulsarAdmin().topics();
boolean exists = false;
try {
Expand Down Expand Up @@ -397,32 +401,48 @@ public void createQueue(Queue destination, int partitions, boolean enableFilters
}
} catch (PulsarAdminException error) {
throw Utils.handleException(error);
} catch (Throwable t) {
// if (t instanceof JMSException) {
// throw (JMSException) t;
// }
throw Utils.handleException(t);
} finally {
Utils.clearContext();
}
}

@Override
public void createTopic(Topic destination, int partitions) throws JMSException {
checkArgument(() -> partitions >= 0, "Invalid number of partitions " + partitions);

PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination);
String topicName = factory.getPulsarTopicName(dest);

Utils.setContext(topicName);

try {
PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination);
checkArgument(() -> partitions >= 0, "Invalid number of partitions " + partitions);

checkDestination(
destination, d -> !dest.isVirtualDestination(), "Cannot create a VirtualDestination");

String topicName = factory.getPulsarTopicName(dest);
Topics topics = factory.ensurePulsarAdmin().topics();

try {
PartitionedTopicMetadata partitionedTopicMetadata =
topics.getPartitionedTopicMetadata(topicName);

checkDestination(
destination,
d -> partitionedTopicMetadata.partitions != partitions,
"Destination exists and it has a different number of partitions "
+ partitionedTopicMetadata.partitions
+ " is different from "
+ partitions);

} catch (PulsarAdminException.NotFoundException notFound) {
// ok
}

try {
if (partitions > 0) {
topics.createPartitionedTopic(topicName, partitions);
Expand All @@ -432,21 +452,33 @@ public void createTopic(Topic destination, int partitions) throws JMSException {
} catch (PulsarAdminException.ConflictException exists) {
throw new InvalidDestinationException("Topic " + topicName + " already exists");
}

} catch (PulsarAdminException error) {
throw Utils.handleException(error);

} catch (Throwable t) {
// if (t instanceof JMSException) {
// throw (JMSException) t;
// }
throw Utils.handleException(t);
} finally {
Utils.clearContext();
}
}

@Override
public void setQueueSubscriptionSelector(
Queue destination, boolean enableFilters, String selector) throws JMSException {
PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination);
String topicName = factory.getPulsarTopicName(dest);
String subscriptionName = factory.getQueueSubscriptionName(dest);
Utils.setContext(topicName);
try {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why move try?

PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination);
String topicName = factory.getPulsarTopicName(dest);
String subscriptionName = factory.getQueueSubscriptionName(dest);
doUpdateSubscriptionSelector(enableFilters, selector, topicName, subscriptionName);
} catch (PulsarAdminException error) {
} catch (Throwable error) { // catch everything
throw Utils.handleException(error);
} finally {
Utils.clearContext();
}
}

Expand All @@ -473,12 +505,15 @@ private void doUpdateSubscriptionSelector(
public void setSubscriptionSelector(
Topic destination, String subscriptionName, boolean enableFilters, String selector)
throws JMSException {
PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination);
String topicName = factory.getPulsarTopicName(dest);
Utils.setContext(topicName);
try {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why move try?

PulsarDestination dest = PulsarConnectionFactory.toPulsarDestination(destination);
String topicName = factory.getPulsarTopicName(dest);
doUpdateSubscriptionSelector(enableFilters, selector, topicName, subscriptionName);
} catch (PulsarAdminException error) {
} catch (Throwable error) {
throw Utils.handleException(error);
} finally {
Utils.clearContext();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,43 +328,51 @@ public boolean hasSomePrefetchedMessages() {

synchronized Message receiveWithTimeoutAndValidateType(long timeout, Class expectedType)
throws JMSException {
checkNotClosed();
if (listener != null) {
throw new IllegalStateException("cannot receive if you have a messageListener");
}
// time to wait for the Connection to "start"
final int acquireConnectionStartTime =
timeout == Long.MAX_VALUE ? Integer.MAX_VALUE : (int) timeout;
// time to wait for each cycle
final int stepTimeout = timeout < 100 ? ((int) timeout) : 100;
final long start = System.currentTimeMillis();
return session.executeOperationIfConnectionStarted(
() -> {
do {
Message result =
session.executeCriticalOperation(
() -> {
try {
Consumer<?> consumer = getConsumer();
org.apache.pulsar.client.api.Message<?> message =
consumer.receive(stepTimeout, TimeUnit.MILLISECONDS);
if (message == null) {
return null;
Utils.setContext(destination.getName());
try {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add try?

checkNotClosed();
if (listener != null) {
throw Utils.handleException(
new IllegalStateException("cannot receive if you have a messageListener"));
}
final int acquireConnectionStartTime =
timeout == Long.MAX_VALUE ? Integer.MAX_VALUE : (int) timeout;
final int stepTimeout = timeout < 100 ? ((int) timeout) : 100;
final long start = System.currentTimeMillis();
return session.executeOperationIfConnectionStarted(
() -> {
do {
Message result =
session.executeCriticalOperation(
() -> {
try {
Consumer<?> consumer = getConsumer();
org.apache.pulsar.client.api.Message<?> message =
consumer.receive(stepTimeout, TimeUnit.MILLISECONDS);
if (message == null) {
return null;
}
return handleReceivedMessage(
message, consumer, expectedType, null, noLocal);
} catch (Exception err) {
throw Utils.handleException(err);
}
return handleReceivedMessage(
message, consumer, expectedType, null, noLocal);
} catch (Exception err) {
throw Utils.handleException(err);
}
});
if (result != null) {
return result;
}
} while (System.currentTimeMillis() - start < timeout && !session.isClosed());

return null;
},
acquireConnectionStartTime);
});
if (result != null) {
return result;
}
} while (System.currentTimeMillis() - start < timeout && !session.isClosed());
return null;
},
acquireConnectionStartTime);
} catch (Throwable t) {
// if (t instanceof JMSException) {
// throw (JMSException) t;
// }
throw Utils.handleException(t);
} finally {
Utils.clearContext();
}
}

/**
Expand Down
Loading
Loading