-
Notifications
You must be signed in to change notification settings - Fork 22
AS-5201: include topic name in all exceptions #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -150,6 +150,13 @@ | |
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>junit-jupiter</artifactId> | ||
| <version>${testcontainers.version}</version> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
|
@@ -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> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
|
@@ -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); | ||
|
|
@@ -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 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -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 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
|---|---|---|
|
|
@@ -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 { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
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