Skip to content

Commit

Permalink
update to use a broker.xml configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkorynta committed Jun 14, 2024
1 parent d8dbc40 commit 2da9087
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@

package cwms.cda.api.messaging;

import hec.io.FilePath;
import hec.io.HecFileImpl;
import hec.util.XMLUtilities;
import oracle.jms.AQjmsFactory;
import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.ActiveMQServers;
import org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import javax.annotation.Resource;
import javax.jms.ConnectionFactory;
Expand All @@ -41,6 +47,9 @@
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.sql.DataSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.net.InetAddress;

@WebListener
Expand All @@ -58,15 +67,16 @@ public void contextInitialized(ServletContextEvent servletContextEvent) {
camelContext = new DefaultCamelContext();
TopicConnectionFactory connectionFactory = AQjmsFactory.getTopicConnectionFactory(new DataSourceWrapper(cwms), true);
camelContext.addComponent("oracleAQ", JmsComponent.jmsComponent(connectionFactory));
//TODO: determine how the port is configured
String activeMqUrl = "tcp://" + InetAddress.getLocalHost().getHostName() + ":61616?protocols=STOMP&webSocketEncoderType=text";
ActiveMQServer server = ActiveMQServers.newActiveMQServer(new ConfigurationImpl()
.addAcceptorConfiguration("tcp", activeMqUrl)
.setPersistenceEnabled(false)
// .setJournalDirectory("build/data/journal")
//Need to update to verify roles
.setSecurityEnabled(false)
.addAcceptorConfiguration("invm", "vm://0"));
File brokerXmlFile = new File("src/test/resources/tomcat/conf/broker.xml").getAbsoluteFile();
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
dbFactory.setNamespaceAware(true);
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(brokerXmlFile);
doc.getDocumentElement().normalize();
Element rootElement = doc.getDocumentElement();
FileConfiguration configuration = new FileConfiguration();
configuration.parse(rootElement, brokerXmlFile.toURI().toURL());
ActiveMQServer server = ActiveMQServers.newActiveMQServer(configuration);
ConnectionFactory artemisConnectionFactory = new ActiveMQJMSConnectionFactory("vm://0");
camelContext.addComponent("artemis", JmsComponent.jmsComponent(artemisConnectionFactory));
camelContext.addRoutes(new RouteBuilder() {
Expand Down
39 changes: 39 additions & 0 deletions cwms-data-api/src/test/resources/tomcat/conf/broker.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version='1.0'?>

<!--
~ MIT License
~
~ Copyright (c) 2024 Hydrologic Engineering Center
~
~ Permission is hereby granted, free of charge, to any person obtaining a copy
~ of this software and associated documentation files (the "Software"), to deal
~ in the Software without restriction, including without limitation the rights
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
~ copies of the Software, and to permit persons to whom the Software is
~ furnished to do so, subject to the following conditions:
~
~ The above copyright notice and this permission notice shall be included in all
~ copies or substantial portions of the Software.
~
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
~ SOFTWARE.
-->

<configuration xmlns="urn:activemq"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/artemis-server.xsd">
<core xmlns="urn:activemq:core">
<name>ActiveMQServer</name>
<persistence-enabled>false</persistence-enabled>
<security-enabled>false</security-enabled>
<acceptors>
<acceptor name="artemis">tcp://localhost:61616?httpEnabled=true</acceptor>
<acceptor name="invm">vm://0</acceptor>
</acceptors>
</core>
</configuration>
2 changes: 1 addition & 1 deletion websocket-testing/src/main/javascript/stomp-ws-testing.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {WebSocket} from 'ws';
Object.assign(global, {WebSocket});
const client = new Client({
logRawCommunication: true,
brokerURL: 'ws://tacocat:61616/topic', connectionTimeout: 1000, onConnect: () => {
brokerURL: 'ws://localhost:61616/topic', connectionTimeout: 1000, onConnect: () => {
console.log("Connected")
client.subscribe('SWT_TS_STORED', message => {
console.log(`Received: ${message.body}`);
Expand Down

0 comments on commit 2da9087

Please sign in to comment.