@GET @Produces(APPLICATION_JSON) @Path("/{subscriptionName}/undelivered") @ApiOperation(value = "Get latest undelivered messages", response = List.class, httpMethod = HttpMethod.GET) public Response getLatestUndeliveredMessages(@PathParam("topicName") String qualifiedTopicName, @PathParam("subscriptionName") String subscriptionName) { List<SentMessageTrace> result = subscriptionService.getLatestUndeliveredMessagesTrackerLogs( fromQualifiedName(qualifiedTopicName), subscriptionName ); return Response.status(OK).entity(result).build(); }
@GET @Produces(APPLICATION_JSON) @ApiOperation(value = "Lists subscriptions", response = List.class, httpMethod = HttpMethod.GET) public List<String> list( @PathParam("topicName") String qualifiedTopicName, @DefaultValue("false") @QueryParam("tracked") boolean tracked) { return tracked ? subscriptionService.listTrackedSubscriptionNames(fromQualifiedName(qualifiedTopicName)) : subscriptionService.listSubscriptionNames(fromQualifiedName(qualifiedTopicName)); }
@Override public void onTopicBlacklisted(String qualifiedTopicName) { Optional<Topic> topic = Optional.ofNullable( Optional.ofNullable( topicCache.get(qualifiedTopicName)).map(CachedTopic::getTopic).orElseGet(() -> topicRepository.getTopicDetails(TopicName.fromQualifiedName(qualifiedTopicName)))); topic.ifPresent(t -> topicCache.put(qualifiedTopicName, bannedTopic(t))); }
@Override public void onTopicUnblacklisted(String qualifiedTopicName) { Optional<Topic> topic = Optional.ofNullable( Optional.ofNullable( topicCache.get(qualifiedTopicName)).map(CachedTopic::getTopic).orElseGet(() -> topicRepository.getTopicDetails(TopicName.fromQualifiedName(qualifiedTopicName)))); topic.ifPresent(t -> topicCache.put(qualifiedTopicName, cachedTopic(t))); }
@GET @Produces(APPLICATION_JSON) @Path("/{subscriptionName}") @ApiOperation(value = "Get subscription details", response = Subscription.class, httpMethod = HttpMethod.GET) public Subscription get(@PathParam("topicName") String qualifiedTopicName, @PathParam("subscriptionName") String subscriptionName) { return subscriptionService.getSubscriptionDetails(fromQualifiedName(qualifiedTopicName), subscriptionName); }
@GET @Produces(APPLICATION_JSON) @Path("/{topicName}/preview") @ApiOperation(value = "Topic publisher preview", httpMethod = HttpMethod.GET) public List<MessageTextPreview> getPreview(@PathParam("topicName") String qualifiedTopicName) { return topicService.previewText(TopicName.fromQualifiedName(qualifiedTopicName)); }
@GET @Produces(APPLICATION_JSON) @Path("/{subscriptionName}/undelivered/last") @ApiOperation(value = "Get latest undelivered message", response = SentMessageTrace.class, httpMethod = HttpMethod.GET) public Response getLatestUndeliveredMessage(@PathParam("topicName") String qualifiedTopicName, @PathParam("subscriptionName") String subscriptionName) { Optional<SentMessageTrace> result = subscriptionService.getLatestUndeliveredMessage( fromQualifiedName(qualifiedTopicName), subscriptionName ); return result.isPresent() ? Response.status(OK).entity(result.get()).build() : responseStatus(NOT_FOUND); }
@GET @Produces(APPLICATION_JSON) @Path("/{topicName}") @ApiOperation(value = "Topic details", httpMethod = HttpMethod.GET) public TopicWithSchema get(@PathParam("topicName") String qualifiedTopicName) { return topicService.getTopicWithSchema(TopicName.fromQualifiedName(qualifiedTopicName)); }
@PUT @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @Path("/{topicName}") @RolesAllowed({Roles.TOPIC_OWNER, Roles.ADMIN}) @ApiOperation(value = "Update topic", httpMethod = HttpMethod.PUT) public Response update(@PathParam("topicName") String qualifiedTopicName, PatchData patch, @Context SecurityContext securityContext) { String updatedBy = securityContext.getUserPrincipal().getName(); topicService.updateTopicWithSchema(TopicName.fromQualifiedName(qualifiedTopicName), patch, updatedBy); return status(Response.Status.OK).build(); }
@DELETE @Path("/{subscriptionName}") @RolesAllowed({Roles.SUBSCRIPTION_OWNER, Roles.TOPIC_OWNER, Roles.ADMIN}) @ApiOperation(value = "Remove subscription", httpMethod = HttpMethod.DELETE) public Response remove(@PathParam("topicName") String qualifiedTopicName, @PathParam("subscriptionName") String subscriptionId, @Context SecurityContext securityContext) { subscriptionService.removeSubscription(fromQualifiedName(qualifiedTopicName), subscriptionId, securityContext.getUserPrincipal().getName()); return responseStatus(OK); }
public void deleteAllSchemaVersions(String qualifiedTopicName) { if (!topicProperties.isRemoveSchema()) { throw new SchemaRemovalDisabledException(); } rawSchemaClient.deleteAllSchemaVersions(fromQualifiedName(qualifiedTopicName)); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenInvalidQualifiedNameProvided() { // when & then TopicName.fromQualifiedName("invalidQualifiedName"); }
public void markDiscarded(MessageMetadata messageMetadata, Subscription subscription, String reason) { TopicName topicName = fromQualifiedName(messageMetadata.getTopic()); metrics.counter(Counters.DISCARDED, topicName, messageMetadata.getSubscription()).inc(); metrics.meter(Meters.DISCARDED_METER).mark(); metrics.meter(Meters.DISCARDED_TOPIC_METER, topicName).mark(); metrics.meter(Meters.DISCARDED_SUBSCRIPTION_METER, topicName, messageMetadata.getSubscription()).mark(); metrics.decrementInflightCounter(subscription); trackers.get(subscription).logDiscarded(messageMetadata, reason); } }
private static TopicName escapedTopicName(String qualifiedTopicName) { TopicName topicName = fromQualifiedName(qualifiedTopicName); return new TopicName( escapeMetricsReplacementChar(topicName.getGroupName()), topicName.getName() ); }
@Test public void shouldHandleDottedGroupName() { // given TopicName topicName = TopicName.fromQualifiedName("group.topic"); // when & then assertThat(topicName.getGroupName()).isEqualTo("group"); assertThat(topicName.getName()).isEqualTo("topic"); }
@Test public void shouldReadValueFromTopicMetric() { // given when(sharedCounter.getValue("/hermes/groups/test/topics/topic/metrics/published")).thenReturn(10L); // when long value = storage.getTopicPublishedCounter(TopicName.fromQualifiedName("test.topic")); // then assertThat(value).isEqualTo(10); }
@Test public void shouldCountInflightNodes() throws Exception { // given when(ephemeralCounter.countOccurrences("/hermes/consumers", "/groups/test/topics/topic/subscriptions/sub/metrics/inflight")) .thenReturn(16); // when long value = storage.countInflightNodes(TopicName.fromQualifiedName("test.topic"), "sub"); // then assertThat(value).isEqualTo(16); }
@Test public void shouldConvertQualifiedName() { // given TopicName topicName = new TopicName("group1", "topic1"); // when & then assertThat(TopicName.fromQualifiedName(topicName.qualifiedName())).isEqualTo(topicName); }
@Test public void shouldNotIncrementSharedCounterForNonExistingSubscription() { //given TopicName topicName = TopicName.fromQualifiedName("test.topic"); String subscriptionName = "sub"; doThrow(new SubscriptionNotExistsException(topicName, subscriptionName)) .when(subscriptionRepository).ensureSubscriptionExists(topicName, subscriptionName); //when storage.setSubscriptionDeliveredCounter(topicName, subscriptionName, 1L); //then verifyZeroInteractions(sharedCounter); }
@Test public void shouldIncrementTopicMetricUsingSharedCounter() { //when storage.setTopicPublishedCounter(TopicName.fromQualifiedName("test.topic"), 10); // then verify(sharedCounter).increment("/hermes/groups/test/topics/topic/metrics/published", 10); }