-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from TAMULib/b03880-b03881-b03882-listen-to-cap
B03880 b03881 b03882 Using messaging broker to listen for updates
- Loading branch information
Showing
21 changed files
with
143 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/main/java/edu/tamu/iiif/service/MessageListenerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package edu.tamu.iiif.service; | ||
|
||
import static edu.tamu.iiif.utility.StringUtility.encode; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.stereotype.Service; | ||
|
||
import edu.tamu.iiif.controller.ManifestRequest; | ||
import edu.tamu.iiif.model.RedisManifest; | ||
import edu.tamu.iiif.model.repo.RedisManifestRepo; | ||
import edu.tamu.weaver.messaging.annotation.WeaverMessageListener; | ||
import edu.tamu.weaver.messaging.config.MessagingConfig; | ||
import edu.tamu.weaver.messaging.model.MessageAction; | ||
|
||
@Service | ||
@Profile("weaver-messaging") | ||
@Import(MessagingConfig.class) | ||
public class MessageListenerService { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(MessageListenerService.class); | ||
|
||
@Autowired | ||
private RedisManifestRepo manifestRepo; | ||
|
||
@Autowired | ||
private List<ManifestService> manifestServices; | ||
|
||
@WeaverMessageListener(destination = "${messaging.channels.cap:cap}", containerFactory = "topicContainerFactory") | ||
private void update(Map<String, String> message) { | ||
MessageAction action = MessageAction.valueOf(message.get("action")); | ||
switch (action) { | ||
case CREATE: | ||
case DELETE: | ||
case REFRESH: | ||
case UPDATE: | ||
updateManifest(message.get("id")); | ||
break; | ||
case READ: | ||
default: | ||
break; | ||
} | ||
|
||
} | ||
|
||
private void updateManifest(String id) { | ||
List<RedisManifest> manifests = manifestRepo.findByPath(encode(id)); | ||
manifests.stream().forEach(manifest -> { | ||
manifestServices.stream().filter(manifestService -> manifestService.getManifestType().equals(manifest.getType()) && manifestService.getRepository().equals(manifest.getRepository())).forEach(manifestService -> { | ||
try { | ||
manifestService.getManifest(ManifestRequest.of(manifest)); | ||
} catch (IOException | URISyntaxException e) { | ||
if (logger.isDebugEnabled()) { | ||
e.printStackTrace(); | ||
} | ||
logger.info(String.format("Unable to get %s %s manifest for %s!", manifest.getRepository(), manifest.getType(), manifest.getPath())); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.