-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2379 added activemq dependency; implemented event publishing to Acti…
…veMQ
- Loading branch information
Showing
6 changed files
with
131 additions
and
38 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
74 changes: 74 additions & 0 deletions
74
...a-manager-impl/src/main/java/io/subutai/core/environment/metadata/impl/EventProducer.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,74 @@ | ||
package io.subutai.core.environment.metadata.impl; | ||
|
||
|
||
import javax.jms.Connection; | ||
import javax.jms.DeliveryMode; | ||
import javax.jms.Destination; | ||
import javax.jms.JMSException; | ||
import javax.jms.MessageProducer; | ||
import javax.jms.Session; | ||
import javax.jms.TextMessage; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.apache.activemq.ActiveMQConnectionFactory; | ||
|
||
|
||
public class EventProducer implements Runnable | ||
{ | ||
private static final Logger LOG = LoggerFactory.getLogger( EventProducer.class ); | ||
private final String destination; | ||
private String message; | ||
|
||
private String brokerURL; | ||
private ActiveMQConnectionFactory connectionFactory; | ||
|
||
|
||
public EventProducer( final String brokerURL, final String destination, final String message ) | ||
{ | ||
this.brokerURL = brokerURL; | ||
this.destination = destination; | ||
this.message = message; | ||
// Create a ConnectionFactory | ||
connectionFactory = new ActiveMQConnectionFactory( this.brokerURL ); | ||
} | ||
|
||
|
||
@Override | ||
public void run() | ||
{ | ||
// Create a Connection | ||
Connection connection = null; | ||
try | ||
{ | ||
connection = connectionFactory.createConnection(); | ||
|
||
connection.start(); | ||
|
||
// Create a Session | ||
Session session = connection.createSession( false, Session.AUTO_ACKNOWLEDGE ); | ||
|
||
// Create the destination (Topic or Queue) | ||
Destination destination = session.createTopic( this.destination ); | ||
|
||
// Create a MessageProducer from the Session to the Topic or Queue | ||
MessageProducer producer = session.createProducer( destination ); | ||
producer.setDeliveryMode( DeliveryMode.NON_PERSISTENT ); | ||
|
||
// Create a messages | ||
TextMessage message = session.createTextMessage( this.message ); | ||
|
||
// Tell the producer to send the message | ||
producer.send( message ); | ||
|
||
// Clean up | ||
session.close(); | ||
connection.close(); | ||
} | ||
catch ( JMSException e ) | ||
{ | ||
LOG.error( e.getMessage(), e ); | ||
} | ||
} | ||
} |
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
11 changes: 11 additions & 0 deletions
11
management/server/subutai-hub-share/src/main/java/io/subutai/hub/share/Utils.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,11 @@ | ||
package io.subutai.hub.share; | ||
|
||
|
||
public class Utils | ||
{ | ||
public static String buildSubutaiOrigin( final String environmentId, final String peerId, | ||
final String containerId ) | ||
{ | ||
return String.format( "%s.%s.%s", environmentId, peerId, containerId, environmentId ); | ||
} | ||
} |
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