SlideShare a Scribd company logo
1 of 37
Download to read offline
APACHE SLING & FRIENDS TECH MEETUP

BERLIN, 23-25 SEPTEMBER 2013

Inter-Sling communication with a message queue
Tomasz Rękawek
Agenda
•  Code bookmarks
•  http://bit.ly/adaptto-jms
•  Case 1: shared session
•  Running ActiveMQ in Sling
•  JMS connection provider
•  Case 2: JMS-based discovery API
implementation
•  Sling Message Listener
•  Case 3: Reverse replication request
•  Targeting instance by its run mode
adaptTo() 2013
 2	
  
adaptTo() 2013
 3
Solution overview
Shared session
Shared session
•  We have n publishes and the dispatcher
with stickySession enabled
•  We use the servlet session
•  In case one publish stops responding, the
user will be redirected to the other publish
•  We want the session to be transferred too
adaptTo() 2013
 4	
  
JMS-based shared session
Dispatcher+
Publish+1+
Publish+2+
Publish+3+
Publish+3+
JMS+
Update+shared+
session+
Session+has+been+changed+
Shared+session+storage+–+stores+session+from+all+
publishes,+with+assigned+unique+shared+session+id+
Request+
Cookie+containing+unique+shared+session+id+(different+
than+JSESSION_ID)+and+unique+instance+id+
adaptTo() 2013
 5	
  
Shared session
•  If a publish notices that the instance id in
the cookie is different from its own, it’ll
copy shared session values to the
HttpSession	
  
•  The Administrator can configure names of
the shared session properties (as a list of
regular expressions)	
  
adaptTo() 2013
 6	
  
Shared session – demo
•  Local infrastructure description:
•  One author + two publishes
•  All available under local.cq	
  domain
•  We can switch between publishes using ?publish2	
  
query string
•  http://local.cq/bin/cognifide/session.txt
•  http://local.cq/bin/cognifide/session.txt/add
•  http://local.cq/bin/cognifide/session.txt?
publish2
adaptTo() 2013
 7	
  
adaptTo() 2013
 8
Shared session implementation details
Integrating ActiveMQ
Rough start: dependencies
•  I tried to use the activemq-­‐core	
  package.
This is what I saw in the /system/console:
adaptTo() 2013
 9	
  
Providing necessary dependencies
•  Some dependencies are taken from other OSGi
bundles – we don’t worry about them
•  Some have to be embedded
<Embed-­‐Dependency>activemq-­‐core,geronimo-­‐j2ee-­‐
management_1.1_spec,ejb-­‐api,jaxrpc-­‐api</Embed-­‐Dependency>	
  
•  Some can be ignored
•  Check the original pom.xml	
  for optional
dependencies
<Import-­‐Package>	
  
!javax.jmdns.*,!org.apache.activeio.*,!
org.apache.activemq.jaas.*,!org.apache.camel.*,!
org.apache.commons.net.*,…,*	
  
</Import-­‐Package>	
  
adaptTo() 2013
 10	
  
Result: sling-­‐jms-­‐activemq	
  
•  We’ve created an OSGi bundle with all
necessary dependencies embedded
•  Optional dependencies are ignored and
marked not-to-import
•  Bundle provides ActiveMQ to any Sling
instance
adaptTo() 2013
 11	
  
adaptTo() 2013
 12
Shared session implementation details
JMS Connection Provider
Creating JMS connection with ActiveMQ
adaptTo() 2013
 13
import	
  javax.jms.Connection;	
  
import	
  org.apache.activemq.ActiveMQConnectionFactory;	
  
	
  
ActiveMQConnectionFactory	
  factory;	
  
factory	
  =	
  new	
  ActiveMQConnectionFactory();	
  
Connection	
  connection	
  =	
  factory.createConnection();	
  
•  In order to create JMS connection we need
to import some ActiveMQ classes:
•  So all JMS-related code will be also dependent
on the ActiveMQ
•  What if we want to change JMS
implementation?
JMS connection provider	
  
•  We use OSGi to separate JMS implementation
from it’s interface
•  JmsConnectionProvider – custom OSGi
service providing javax.jms.Connection	
  
•  Bundle sling-­‐jms-­‐api	
  contains service
interface
•  Implementation: sling-­‐jms-­‐impl-­‐activemq	
  
•  Using sling-­‐jms-­‐api	
  and the connection
provider makes us independent from the JMS
implementation
adaptTo() 2013
 14	
  
Example usage of JMS connection provider	
  
@Component	
  
public	
  class	
  MyComponent	
  implements	
  MessageListener	
  {	
  
	
  
	
  	
  	
  @Reference	
  
	
  	
  	
  private	
  JmsConnectionProvider	
  connectionProvider;	
  
	
  
	
  	
  	
  private	
  javax.jms.Connection	
  connection;	
  
	
  
	
  	
  	
  @Activate	
  
	
  	
  	
  protected	
  void	
  activate()	
  throws	
  JMSException	
  {	
  
	
  	
  	
  	
  	
  	
  connection	
  =	
  connectionProvider.getConnection();	
  
	
  	
  	
  }	
  
	
  
	
  	
  	
  @Deactivate	
  
	
  	
  	
  protected	
  void	
  deactivate()	
  throws	
  JMSException	
  {	
  
	
  	
  	
  	
  	
  	
  connection.close();	
  
	
  	
  	
  }	
  
}	
  
adaptTo() 2013
 15	
  
adaptTo() 2013
 16
API overview & our JMS implementation
Discovery API
Sling Discovery API
•  New Sling API
•  Each instance can expose a list of key-value
properties to other instances
•  Example usage: metadata for workflow
offloading in CQ
•  Properties are not meant to be messaging
tool, they shouldn’t change too often
•  Instances are grouped into clusters, each
cluster has elected leader
adaptTo() 2013
 17	
  
Topology
Red$cluster$ Blue$cluster$
$
$
$
Orange$cluster$
Instance$1$
Instance$2$ Instance$3$
Instance$A$
Instance$B$ Instance$C$
Single$Sling$
adaptTo() 2013
 18	
  
Discovery OSGi services
•  DiscoveryService provides TopologyView	
  
•  Custom instance properties can be added
with PropertyProvider implementations
•  Changes in topology can be observed with
TopologyEventListener
adaptTo() 2013
 19	
  
JMS discovery implementation
•  There is a default HTTP-based
implementation
•  requires providing all instance URLs on each
instance
•  But JMS is a natural choice for the
transport layer here
•  sling-­‐jms-­‐discovery	
  – a new, JMS-based
discovery implementation that doesn’t
require any configuration
adaptTo() 2013
 20	
  
Discovery election
•  If some instance notices there is no leader for
some cluster, it sends message: WHO_IS_LEADER	
  
•  If no one responds in 10 seconds, it sends the
second message: ELECTION	
  
•  Every instance in a given cluster has to
respond with their Sling instance id in the VOTE
message
•  After 5 seconds instance with the smallest id
is chosen and it sends the I_AM_LEADER
message
adaptTo() 2013
 21	
  
Discovery – demo
•  http://local.cq:4503/bin/jms/discovery/info.txt
adaptTo() 2013
 22	
  
adaptTo() 2013
 23
JMS discovery implementation details
Sling Message Consumer
Sling Message Listener
Writing JMS consumers in OSGi is all about
@Component	
  
public	
  class	
  MyComponent	
  implements	
  MessageListener	
  {	
  
	
  
	
  	
  	
  @Reference	
  
	
  	
  	
  private	
  JmsConnectionProvider	
  connectionProvider;	
  
	
  	
  	
  private	
  Connection	
  connection;	
  
	
  	
  	
  private	
  Session	
  session;	
  
	
  	
  	
  private	
  MessageConsumer	
  consumer;	
  
	
  
	
  	
  	
  @Activate	
  
	
  	
  	
  protected	
  void	
  activate()	
  throws	
  JMSException	
  {	
  
	
  	
  	
  	
  	
  	
  connection	
  =	
  connectionProvider.getConnection();	
  
	
  	
  	
  	
  	
  	
  session	
  =	
  connection.createSession(false,	
  Session.AUTO_ACKNOWLEDGE);	
  
	
  	
  	
  	
  	
  	
  Destination	
  dest	
  =	
  session.createTopic("my	
  topic");	
  
	
  	
  	
  	
  	
  	
  consumer	
  =	
  session.createConsumer(dest);	
  
	
  	
  	
  	
  	
  	
  consumer.setMessageListener(this);	
  
	
  	
  	
  	
  	
  	
  connection.start();	
  
	
  	
  	
  }	
  
	
  
	
  	
  	
  @Deactivate	
  
	
  	
  	
  protected	
  void	
  deactivate()	
  throws	
  JMSException	
  {	
  
	
  	
  	
  	
  	
  	
  consumer.close();	
  
	
  	
  	
  	
  	
  	
  session.close();	
  
	
  	
  	
  	
  	
  	
  connection.close();	
  
	
  	
  	
  }	
  
}	
  
adaptTo() 2013
 24	
  
Sling Message Listener
Why don’t we
@SlingMessageConsumer(	
  
	
  	
  	
  	
  destinationType	
  =	
  DestinationType.TOPIC,	
  
	
  	
  	
  	
  subject	
  =	
  "my	
  topic")	
  
public	
  class	
  MyComponent	
  implements	
  MessageListener	
  {	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  public	
  void	
  onMessage(Message	
  msg)	
  {	
  
//	
  …	
  
adaptTo() 2013
 25	
  
•  @SlingMessageConsumer annotation is transformed into @Service,
@Component	
  and @Properties by our sling-­‐jms-­‐scr	
  plugin	
  
•  MessageListener services are collected by our
MessageConsumerRegistry OSGi component
•  Registry component creates JMS consumers and forward messages to
appropriate listeners
Sling Message Listener – filtering
In the message listener configuration you can
add the filter property to filter out incoming
messages. Use the LDAP format:

@SlingMessageConsumer(	
  
	
  	
  	
  destinationType	
  =	
  DestinationType.TOPIC,	
  
	
  	
  	
  subject	
  =	
  "my	
  topic"	
  
	
  	
  	
  filter	
  =	
  "(requestType=VOTE)")	
  
adaptTo() 2013
 26	
  
adaptTo() 2013
 27
Solution overview
Reverse Replication Request
Reverse replication request
•  In CQ, the Author gathers content from publish
instances every 30 seconds (configurable in the
ReverseReplicator service)
•  Why can’t publish send user-generated content to
the Author (push instead of pull)?
•  Security issues – publishes are often in DMZ
•  But publish can inform the Author there is
something new to pull
adaptTo() 2013
 28	
  
Reverse replication request
•  OutboxEventHandler watches the outbox node
and sends information every time there is
some new content to pull
•  ReplicationAgentInvoker receives this
information and invokes the reverse
replication process
•  It’s a good idea to disable the out-of-the-box
ReverseReplicator service, so we don’t have
two reverse replications at the same moment
adaptTo() 2013
 29	
  
Reverse replication request flow
Author'Publish'
User/generated'content'
OutboxEventHandler' Replica<onAgentInvoker'
Reverse'replica<on'agent'Outbox'
Send'JMS'msg'
Pull'content'
adaptTo() 2013
 30	
  
adaptTo() 2013
 31
Reverse replication request implementation details
Targeting messages with the Sling run mode
Send messages only to the Author
•  The outbox event handler should send
messages only to the Author
•  We can filter it manually…
•  …or use @SlingMessageConsumer	
  for the
consumer and add
MessageConsumerProperties.DESTINATION_RUN_MODE	
  to
the message properties
•  Messages will be filtered automatically
adaptTo() 2013
 32	
  
adaptTo() 2013
 33
Final remarks
Extra tools created during JMS research
•  Embedded ActiveMQ broker configurable
within the OSGi component
•  Out-of-the-band JCR binaries transfer
•  You can send a message with metadata and
some JCR path and the binary itself will be
sent via HTTP
•  Utilities to deal with serialization problems
when sending ObjectMessage	
  
adaptTo() 2013
 34	
  
Bundles overview
•  sling-­‐jms-­‐activemq	
  
•  ActiveMQ + dependencies
•  sling-­‐jms-­‐api	
  
•  JMS Connection Provider
•  Sling Message Consumer
•  Blob & Object message utils
•  sling-­‐jms-­‐impl-­‐activemq	
  
•  Implementation of the API tools
•  sling-­‐jms-­‐scr	
  
•  Annotation processor for Sling Message Consumer
•  sling-­‐jms-­‐sandbox	
  
•  Example usage of the API tools
•  Open-sourced use cases
•  sling-­‐jms-­‐discovery	
  
•  cq-­‐jms-­‐replication	
  
•  sling-­‐jms-­‐session	
  
adaptTo() 2013
 35	
  
Try it yourself!
•  https://github.com/Cognifide/PoC-Sling-JMS
•  All bundles
•  Some documentation
•  Temporary repo, will be transferred, so clone it
while you can ;)
adaptTo() 2013
 36	
  
adaptTo() 2013
 37
That’s all folks!

More Related Content

What's hot

AWS 클라우드 비용 최적화를 위한 모범 사례-AWS Summit Seoul 2017
AWS 클라우드 비용 최적화를 위한 모범 사례-AWS Summit Seoul 2017AWS 클라우드 비용 최적화를 위한 모범 사례-AWS Summit Seoul 2017
AWS 클라우드 비용 최적화를 위한 모범 사례-AWS Summit Seoul 2017Amazon Web Services Korea
 
Sling models by Justin Edelson
Sling models by Justin Edelson Sling models by Justin Edelson
Sling models by Justin Edelson AEM HUB
 
AWS 기반 대규모 트래픽 견디기 - 장준엽 (구로디지털 모임) :: AWS Community Day 2017
AWS 기반 대규모 트래픽 견디기 - 장준엽 (구로디지털 모임) :: AWS Community Day 2017AWS 기반 대규모 트래픽 견디기 - 장준엽 (구로디지털 모임) :: AWS Community Day 2017
AWS 기반 대규모 트래픽 견디기 - 장준엽 (구로디지털 모임) :: AWS Community Day 2017AWSKRUG - AWS한국사용자모임
 
Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...
Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...
Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...confluent
 
Amazon EFS (Elastic File System) 이해하고사용하기
Amazon EFS (Elastic File System) 이해하고사용하기Amazon EFS (Elastic File System) 이해하고사용하기
Amazon EFS (Elastic File System) 이해하고사용하기Amazon Web Services Korea
 
Understanding Sling Models in AEM
Understanding Sling Models in AEMUnderstanding Sling Models in AEM
Understanding Sling Models in AEMAccunity Software
 
마이크로 서비스를 위한 AWS Cloud Map & App Mesh - Saeho Kim (AWS Solutions Architect)
마이크로 서비스를 위한 AWS Cloud Map & App Mesh - Saeho Kim (AWS Solutions Architect)마이크로 서비스를 위한 AWS Cloud Map & App Mesh - Saeho Kim (AWS Solutions Architect)
마이크로 서비스를 위한 AWS Cloud Map & App Mesh - Saeho Kim (AWS Solutions Architect)Amazon Web Services Korea
 
AWS Black Belt Online Seminar 2017 Amazon Pinpoint で始めるモバイルアプリのグロースハック
AWS Black Belt Online Seminar 2017 Amazon Pinpoint で始めるモバイルアプリのグロースハックAWS Black Belt Online Seminar 2017 Amazon Pinpoint で始めるモバイルアプリのグロースハック
AWS Black Belt Online Seminar 2017 Amazon Pinpoint で始めるモバイルアプリのグロースハックAmazon Web Services Japan
 
Adobe Experience Manager Core Components
Adobe Experience Manager Core ComponentsAdobe Experience Manager Core Components
Adobe Experience Manager Core ComponentsGabriel Walt
 
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017Amazon Web Services Korea
 
마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트)
마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트) 마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트)
마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트) Amazon Web Services Korea
 
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...Amazon Web Services
 
9월 웨비나 - AWS에서의 네트워크 보안 (이경수 솔루션즈 아키텍트)
9월 웨비나 - AWS에서의 네트워크 보안 (이경수 솔루션즈 아키텍트)9월 웨비나 - AWS에서의 네트워크 보안 (이경수 솔루션즈 아키텍트)
9월 웨비나 - AWS에서의 네트워크 보안 (이경수 솔루션즈 아키텍트)Amazon Web Services Korea
 
Aws glue를 통한 손쉬운 데이터 전처리 작업하기
Aws glue를 통한 손쉬운 데이터 전처리 작업하기Aws glue를 통한 손쉬운 데이터 전처리 작업하기
Aws glue를 통한 손쉬운 데이터 전처리 작업하기Amazon Web Services Korea
 
AWS Lambda 100% 활용하기 :: 김상필 솔루션즈 아키텍트 :: Gaming on AWS 2016
AWS Lambda 100% 활용하기 :: 김상필 솔루션즈 아키텍트 :: Gaming on AWS 2016AWS Lambda 100% 활용하기 :: 김상필 솔루션즈 아키텍트 :: Gaming on AWS 2016
AWS Lambda 100% 활용하기 :: 김상필 솔루션즈 아키텍트 :: Gaming on AWS 2016Amazon Web Services Korea
 
[112]rest에서 graph ql과 relay로 갈아타기 이정우
[112]rest에서 graph ql과 relay로 갈아타기 이정우[112]rest에서 graph ql과 relay로 갈아타기 이정우
[112]rest에서 graph ql과 relay로 갈아타기 이정우NAVER D2
 

What's hot (20)

AWS 클라우드 비용 최적화를 위한 모범 사례-AWS Summit Seoul 2017
AWS 클라우드 비용 최적화를 위한 모범 사례-AWS Summit Seoul 2017AWS 클라우드 비용 최적화를 위한 모범 사례-AWS Summit Seoul 2017
AWS 클라우드 비용 최적화를 위한 모범 사례-AWS Summit Seoul 2017
 
Sling models by Justin Edelson
Sling models by Justin Edelson Sling models by Justin Edelson
Sling models by Justin Edelson
 
AWS 기반 대규모 트래픽 견디기 - 장준엽 (구로디지털 모임) :: AWS Community Day 2017
AWS 기반 대규모 트래픽 견디기 - 장준엽 (구로디지털 모임) :: AWS Community Day 2017AWS 기반 대규모 트래픽 견디기 - 장준엽 (구로디지털 모임) :: AWS Community Day 2017
AWS 기반 대규모 트래픽 견디기 - 장준엽 (구로디지털 모임) :: AWS Community Day 2017
 
Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...
Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...
Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...
 
Amazon EFS (Elastic File System) 이해하고사용하기
Amazon EFS (Elastic File System) 이해하고사용하기Amazon EFS (Elastic File System) 이해하고사용하기
Amazon EFS (Elastic File System) 이해하고사용하기
 
Understanding Sling Models in AEM
Understanding Sling Models in AEMUnderstanding Sling Models in AEM
Understanding Sling Models in AEM
 
마이크로 서비스를 위한 AWS Cloud Map & App Mesh - Saeho Kim (AWS Solutions Architect)
마이크로 서비스를 위한 AWS Cloud Map & App Mesh - Saeho Kim (AWS Solutions Architect)마이크로 서비스를 위한 AWS Cloud Map & App Mesh - Saeho Kim (AWS Solutions Architect)
마이크로 서비스를 위한 AWS Cloud Map & App Mesh - Saeho Kim (AWS Solutions Architect)
 
Sling Models Overview
Sling Models OverviewSling Models Overview
Sling Models Overview
 
AWS Black Belt Online Seminar 2017 Amazon Pinpoint で始めるモバイルアプリのグロースハック
AWS Black Belt Online Seminar 2017 Amazon Pinpoint で始めるモバイルアプリのグロースハックAWS Black Belt Online Seminar 2017 Amazon Pinpoint で始めるモバイルアプリのグロースハック
AWS Black Belt Online Seminar 2017 Amazon Pinpoint で始めるモバイルアプリのグロースハック
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Adobe Experience Manager Core Components
Adobe Experience Manager Core ComponentsAdobe Experience Manager Core Components
Adobe Experience Manager Core Components
 
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017
AWS 고객이 주로 겪는 운영 이슈에 대한 해법-AWS Summit Seoul 2017
 
Deep-Dive: Secure API Management
Deep-Dive: Secure API ManagementDeep-Dive: Secure API Management
Deep-Dive: Secure API Management
 
마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트)
마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트) 마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트)
마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트)
 
Spring boot
Spring bootSpring boot
Spring boot
 
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
Getting Started with Serverless Architectures with Microservices_AWSPSSummit_...
 
9월 웨비나 - AWS에서의 네트워크 보안 (이경수 솔루션즈 아키텍트)
9월 웨비나 - AWS에서의 네트워크 보안 (이경수 솔루션즈 아키텍트)9월 웨비나 - AWS에서의 네트워크 보안 (이경수 솔루션즈 아키텍트)
9월 웨비나 - AWS에서의 네트워크 보안 (이경수 솔루션즈 아키텍트)
 
Aws glue를 통한 손쉬운 데이터 전처리 작업하기
Aws glue를 통한 손쉬운 데이터 전처리 작업하기Aws glue를 통한 손쉬운 데이터 전처리 작업하기
Aws glue를 통한 손쉬운 데이터 전처리 작업하기
 
AWS Lambda 100% 활용하기 :: 김상필 솔루션즈 아키텍트 :: Gaming on AWS 2016
AWS Lambda 100% 활용하기 :: 김상필 솔루션즈 아키텍트 :: Gaming on AWS 2016AWS Lambda 100% 활용하기 :: 김상필 솔루션즈 아키텍트 :: Gaming on AWS 2016
AWS Lambda 100% 활용하기 :: 김상필 솔루션즈 아키텍트 :: Gaming on AWS 2016
 
[112]rest에서 graph ql과 relay로 갈아타기 이정우
[112]rest에서 graph ql과 relay로 갈아타기 이정우[112]rest에서 graph ql과 relay로 갈아타기 이정우
[112]rest에서 graph ql과 relay로 갈아타기 이정우
 

Similar to Inter-Sling communication with message queue

DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkbanq jdon
 
Advanced Node.JS Meetup
Advanced Node.JS MeetupAdvanced Node.JS Meetup
Advanced Node.JS MeetupLINAGORA
 
4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message BrokersPROIDEA
 
OpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConOpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConos890
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slidesDavid Barreto
 
An approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAn approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAndrei Sebastian Cîmpean
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideMohanraj Thirumoorthy
 
Using Sumo Logic - Apr 2018
Using Sumo Logic - Apr 2018Using Sumo Logic - Apr 2018
Using Sumo Logic - Apr 2018Sumo Logic
 
OSGi Cloud Ecosystems (OSGi Users Forum Germany)
OSGi Cloud Ecosystems (OSGi Users Forum Germany)OSGi Cloud Ecosystems (OSGi Users Forum Germany)
OSGi Cloud Ecosystems (OSGi Users Forum Germany)David Bosschaert
 
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Oliver Gierke
 
Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012Droidcon Eastern Europe
 
Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 3camp
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang YoonJesang Yoon
 
The new and smart way to build microservices - Eclipse MicroProfile
The new and smart way to build microservices - Eclipse MicroProfileThe new and smart way to build microservices - Eclipse MicroProfile
The new and smart way to build microservices - Eclipse MicroProfileEmily Jiang
 
Introduction to Lagom Framework
Introduction to Lagom FrameworkIntroduction to Lagom Framework
Introduction to Lagom FrameworkKnoldus Inc.
 
Server-side JS with NodeJS
Server-side JS with NodeJSServer-side JS with NodeJS
Server-side JS with NodeJSLilia Sfaxi
 
OSGi DevCon 2009 Review
OSGi DevCon 2009 ReviewOSGi DevCon 2009 Review
OSGi DevCon 2009 Reviewnjbartlett
 

Similar to Inter-Sling communication with message queue (20)

DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFramework
 
Advanced Node.JS Meetup
Advanced Node.JS MeetupAdvanced Node.JS Meetup
Advanced Node.JS Meetup
 
4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers
 
Grizzly 20080925 V2
Grizzly 20080925 V2Grizzly 20080925 V2
Grizzly 20080925 V2
 
OpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheConOpenWebBeans and DeltaSpike at ApacheCon
OpenWebBeans and DeltaSpike at ApacheCon
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slides
 
An approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSocketsAn approach to responsive, realtime with Backbone.js and WebSockets
An approach to responsive, realtime with Backbone.js and WebSockets
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
 
Using Sumo Logic - Apr 2018
Using Sumo Logic - Apr 2018Using Sumo Logic - Apr 2018
Using Sumo Logic - Apr 2018
 
G pars
G parsG pars
G pars
 
OSGi Cloud Ecosystems (OSGi Users Forum Germany)
OSGi Cloud Ecosystems (OSGi Users Forum Germany)OSGi Cloud Ecosystems (OSGi Users Forum Germany)
OSGi Cloud Ecosystems (OSGi Users Forum Germany)
 
Whoops! Where did my architecture go?
Whoops! Where did my architecture go?Whoops! Where did my architecture go?
Whoops! Where did my architecture go?
 
Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012
 
Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 
The new and smart way to build microservices - Eclipse MicroProfile
The new and smart way to build microservices - Eclipse MicroProfileThe new and smart way to build microservices - Eclipse MicroProfile
The new and smart way to build microservices - Eclipse MicroProfile
 
Introduction to Lagom Framework
Introduction to Lagom FrameworkIntroduction to Lagom Framework
Introduction to Lagom Framework
 
Server-side JS with NodeJS
Server-side JS with NodeJSServer-side JS with NodeJS
Server-side JS with NodeJS
 
OSGi DevCon 2009 Review
OSGi DevCon 2009 ReviewOSGi DevCon 2009 Review
OSGi DevCon 2009 Review
 
Liferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for DevelopersLiferay (DXP) 7 Tech Meetup for Developers
Liferay (DXP) 7 Tech Meetup for Developers
 

More from Tomasz Rękawek

Deep-dive into cloud-native AEM deployments based on Kubernetes
Deep-dive into cloud-native AEM deployments based on KubernetesDeep-dive into cloud-native AEM deployments based on Kubernetes
Deep-dive into cloud-native AEM deployments based on KubernetesTomasz Rękawek
 
Emulating Game Boy in Java
Emulating Game Boy in JavaEmulating Game Boy in Java
Emulating Game Boy in JavaTomasz Rękawek
 
Zero downtime deployments for the Sling-based apps using Docker
Zero downtime deployments for the Sling-based apps using DockerZero downtime deployments for the Sling-based apps using Docker
Zero downtime deployments for the Sling-based apps using DockerTomasz Rękawek
 
CRX2Oak - all the secrets of repository migration
CRX2Oak - all the secrets of repository migrationCRX2Oak - all the secrets of repository migration
CRX2Oak - all the secrets of repository migrationTomasz Rękawek
 
Shooting rabbits with sling
Shooting rabbits with slingShooting rabbits with sling
Shooting rabbits with slingTomasz Rękawek
 

More from Tomasz Rękawek (9)

Radio ad blocker
Radio ad blockerRadio ad blocker
Radio ad blocker
 
Deep-dive into cloud-native AEM deployments based on Kubernetes
Deep-dive into cloud-native AEM deployments based on KubernetesDeep-dive into cloud-native AEM deployments based on Kubernetes
Deep-dive into cloud-native AEM deployments based on Kubernetes
 
Emulating Game Boy in Java
Emulating Game Boy in JavaEmulating Game Boy in Java
Emulating Game Boy in Java
 
Zero downtime deployments for the Sling-based apps using Docker
Zero downtime deployments for the Sling-based apps using DockerZero downtime deployments for the Sling-based apps using Docker
Zero downtime deployments for the Sling-based apps using Docker
 
CRX2Oak - all the secrets of repository migration
CRX2Oak - all the secrets of repository migrationCRX2Oak - all the secrets of repository migration
CRX2Oak - all the secrets of repository migration
 
SlingQuery
SlingQuerySlingQuery
SlingQuery
 
Code metrics
Code metricsCode metrics
Code metrics
 
Sling Dynamic Include
Sling Dynamic IncludeSling Dynamic Include
Sling Dynamic Include
 
Shooting rabbits with sling
Shooting rabbits with slingShooting rabbits with sling
Shooting rabbits with sling
 

Recently uploaded

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

Inter-Sling communication with message queue

  • 1. APACHE SLING & FRIENDS TECH MEETUP BERLIN, 23-25 SEPTEMBER 2013 Inter-Sling communication with a message queue Tomasz Rękawek
  • 2. Agenda •  Code bookmarks •  http://bit.ly/adaptto-jms •  Case 1: shared session •  Running ActiveMQ in Sling •  JMS connection provider •  Case 2: JMS-based discovery API implementation •  Sling Message Listener •  Case 3: Reverse replication request •  Targeting instance by its run mode adaptTo() 2013 2  
  • 3. adaptTo() 2013 3 Solution overview Shared session
  • 4. Shared session •  We have n publishes and the dispatcher with stickySession enabled •  We use the servlet session •  In case one publish stops responding, the user will be redirected to the other publish •  We want the session to be transferred too adaptTo() 2013 4  
  • 6. Shared session •  If a publish notices that the instance id in the cookie is different from its own, it’ll copy shared session values to the HttpSession   •  The Administrator can configure names of the shared session properties (as a list of regular expressions)   adaptTo() 2013 6  
  • 7. Shared session – demo •  Local infrastructure description: •  One author + two publishes •  All available under local.cq  domain •  We can switch between publishes using ?publish2   query string •  http://local.cq/bin/cognifide/session.txt •  http://local.cq/bin/cognifide/session.txt/add •  http://local.cq/bin/cognifide/session.txt? publish2 adaptTo() 2013 7  
  • 8. adaptTo() 2013 8 Shared session implementation details Integrating ActiveMQ
  • 9. Rough start: dependencies •  I tried to use the activemq-­‐core  package. This is what I saw in the /system/console: adaptTo() 2013 9  
  • 10. Providing necessary dependencies •  Some dependencies are taken from other OSGi bundles – we don’t worry about them •  Some have to be embedded <Embed-­‐Dependency>activemq-­‐core,geronimo-­‐j2ee-­‐ management_1.1_spec,ejb-­‐api,jaxrpc-­‐api</Embed-­‐Dependency>   •  Some can be ignored •  Check the original pom.xml  for optional dependencies <Import-­‐Package>   !javax.jmdns.*,!org.apache.activeio.*,! org.apache.activemq.jaas.*,!org.apache.camel.*,! org.apache.commons.net.*,…,*   </Import-­‐Package>   adaptTo() 2013 10  
  • 11. Result: sling-­‐jms-­‐activemq   •  We’ve created an OSGi bundle with all necessary dependencies embedded •  Optional dependencies are ignored and marked not-to-import •  Bundle provides ActiveMQ to any Sling instance adaptTo() 2013 11  
  • 12. adaptTo() 2013 12 Shared session implementation details JMS Connection Provider
  • 13. Creating JMS connection with ActiveMQ adaptTo() 2013 13 import  javax.jms.Connection;   import  org.apache.activemq.ActiveMQConnectionFactory;     ActiveMQConnectionFactory  factory;   factory  =  new  ActiveMQConnectionFactory();   Connection  connection  =  factory.createConnection();   •  In order to create JMS connection we need to import some ActiveMQ classes: •  So all JMS-related code will be also dependent on the ActiveMQ •  What if we want to change JMS implementation?
  • 14. JMS connection provider   •  We use OSGi to separate JMS implementation from it’s interface •  JmsConnectionProvider – custom OSGi service providing javax.jms.Connection   •  Bundle sling-­‐jms-­‐api  contains service interface •  Implementation: sling-­‐jms-­‐impl-­‐activemq   •  Using sling-­‐jms-­‐api  and the connection provider makes us independent from the JMS implementation adaptTo() 2013 14  
  • 15. Example usage of JMS connection provider   @Component   public  class  MyComponent  implements  MessageListener  {          @Reference        private  JmsConnectionProvider  connectionProvider;          private  javax.jms.Connection  connection;          @Activate        protected  void  activate()  throws  JMSException  {              connection  =  connectionProvider.getConnection();        }          @Deactivate        protected  void  deactivate()  throws  JMSException  {              connection.close();        }   }   adaptTo() 2013 15  
  • 16. adaptTo() 2013 16 API overview & our JMS implementation Discovery API
  • 17. Sling Discovery API •  New Sling API •  Each instance can expose a list of key-value properties to other instances •  Example usage: metadata for workflow offloading in CQ •  Properties are not meant to be messaging tool, they shouldn’t change too often •  Instances are grouped into clusters, each cluster has elected leader adaptTo() 2013 17  
  • 19. Discovery OSGi services •  DiscoveryService provides TopologyView   •  Custom instance properties can be added with PropertyProvider implementations •  Changes in topology can be observed with TopologyEventListener adaptTo() 2013 19  
  • 20. JMS discovery implementation •  There is a default HTTP-based implementation •  requires providing all instance URLs on each instance •  But JMS is a natural choice for the transport layer here •  sling-­‐jms-­‐discovery  – a new, JMS-based discovery implementation that doesn’t require any configuration adaptTo() 2013 20  
  • 21. Discovery election •  If some instance notices there is no leader for some cluster, it sends message: WHO_IS_LEADER   •  If no one responds in 10 seconds, it sends the second message: ELECTION   •  Every instance in a given cluster has to respond with their Sling instance id in the VOTE message •  After 5 seconds instance with the smallest id is chosen and it sends the I_AM_LEADER message adaptTo() 2013 21  
  • 22. Discovery – demo •  http://local.cq:4503/bin/jms/discovery/info.txt adaptTo() 2013 22  
  • 23. adaptTo() 2013 23 JMS discovery implementation details Sling Message Consumer
  • 24. Sling Message Listener Writing JMS consumers in OSGi is all about @Component   public  class  MyComponent  implements  MessageListener  {          @Reference        private  JmsConnectionProvider  connectionProvider;        private  Connection  connection;        private  Session  session;        private  MessageConsumer  consumer;          @Activate        protected  void  activate()  throws  JMSException  {              connection  =  connectionProvider.getConnection();              session  =  connection.createSession(false,  Session.AUTO_ACKNOWLEDGE);              Destination  dest  =  session.createTopic("my  topic");              consumer  =  session.createConsumer(dest);              consumer.setMessageListener(this);              connection.start();        }          @Deactivate        protected  void  deactivate()  throws  JMSException  {              consumer.close();              session.close();              connection.close();        }   }   adaptTo() 2013 24  
  • 25. Sling Message Listener Why don’t we @SlingMessageConsumer(          destinationType  =  DestinationType.TOPIC,          subject  =  "my  topic")   public  class  MyComponent  implements  MessageListener  {                    public  void  onMessage(Message  msg)  {   //  …   adaptTo() 2013 25   •  @SlingMessageConsumer annotation is transformed into @Service, @Component  and @Properties by our sling-­‐jms-­‐scr  plugin   •  MessageListener services are collected by our MessageConsumerRegistry OSGi component •  Registry component creates JMS consumers and forward messages to appropriate listeners
  • 26. Sling Message Listener – filtering In the message listener configuration you can add the filter property to filter out incoming messages. Use the LDAP format: @SlingMessageConsumer(        destinationType  =  DestinationType.TOPIC,        subject  =  "my  topic"        filter  =  "(requestType=VOTE)")   adaptTo() 2013 26  
  • 27. adaptTo() 2013 27 Solution overview Reverse Replication Request
  • 28. Reverse replication request •  In CQ, the Author gathers content from publish instances every 30 seconds (configurable in the ReverseReplicator service) •  Why can’t publish send user-generated content to the Author (push instead of pull)? •  Security issues – publishes are often in DMZ •  But publish can inform the Author there is something new to pull adaptTo() 2013 28  
  • 29. Reverse replication request •  OutboxEventHandler watches the outbox node and sends information every time there is some new content to pull •  ReplicationAgentInvoker receives this information and invokes the reverse replication process •  It’s a good idea to disable the out-of-the-box ReverseReplicator service, so we don’t have two reverse replications at the same moment adaptTo() 2013 29  
  • 30. Reverse replication request flow Author'Publish' User/generated'content' OutboxEventHandler' Replica<onAgentInvoker' Reverse'replica<on'agent'Outbox' Send'JMS'msg' Pull'content' adaptTo() 2013 30  
  • 31. adaptTo() 2013 31 Reverse replication request implementation details Targeting messages with the Sling run mode
  • 32. Send messages only to the Author •  The outbox event handler should send messages only to the Author •  We can filter it manually… •  …or use @SlingMessageConsumer  for the consumer and add MessageConsumerProperties.DESTINATION_RUN_MODE  to the message properties •  Messages will be filtered automatically adaptTo() 2013 32  
  • 34. Extra tools created during JMS research •  Embedded ActiveMQ broker configurable within the OSGi component •  Out-of-the-band JCR binaries transfer •  You can send a message with metadata and some JCR path and the binary itself will be sent via HTTP •  Utilities to deal with serialization problems when sending ObjectMessage   adaptTo() 2013 34  
  • 35. Bundles overview •  sling-­‐jms-­‐activemq   •  ActiveMQ + dependencies •  sling-­‐jms-­‐api   •  JMS Connection Provider •  Sling Message Consumer •  Blob & Object message utils •  sling-­‐jms-­‐impl-­‐activemq   •  Implementation of the API tools •  sling-­‐jms-­‐scr   •  Annotation processor for Sling Message Consumer •  sling-­‐jms-­‐sandbox   •  Example usage of the API tools •  Open-sourced use cases •  sling-­‐jms-­‐discovery   •  cq-­‐jms-­‐replication   •  sling-­‐jms-­‐session   adaptTo() 2013 35  
  • 36. Try it yourself! •  https://github.com/Cognifide/PoC-Sling-JMS •  All bundles •  Some documentation •  Temporary repo, will be transferred, so clone it while you can ;) adaptTo() 2013 36