-
Notifications
You must be signed in to change notification settings - Fork 1
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 #26 from alliance-genome/add_queuing
Added queuing and reorg
- Loading branch information
Showing
7 changed files
with
119 additions
and
40 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
68 changes: 68 additions & 0 deletions
68
src/main/java/org/alliancegenome/curation_api/consumers/GeneDTOConsumer.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,68 @@ | ||
package org.alliancegenome.curation_api.consumers; | ||
|
||
import java.util.concurrent.*; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.context.control.ActivateRequestContext; | ||
import javax.enterprise.event.Observes; | ||
import javax.inject.Inject; | ||
import javax.jms.*; | ||
|
||
import org.alliancegenome.curation_api.model.ingest.json.dto.GeneDTO; | ||
import org.alliancegenome.curation_api.services.GeneService; | ||
|
||
import io.quarkus.runtime.*; | ||
import lombok.extern.jbosslog.JBossLog; | ||
|
||
@JBossLog | ||
@ApplicationScoped | ||
public class GeneDTOConsumer implements Runnable { | ||
|
||
@Inject GeneService geneService; | ||
|
||
@Inject ConnectionFactory connectionFactory1; | ||
@Inject ConnectionFactory connectionFactory2; | ||
|
||
private JMSProducer producer; | ||
private JMSContext context; | ||
|
||
private int threadCount = 4; | ||
|
||
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(threadCount); | ||
|
||
void onStart(@Observes StartupEvent ev) { | ||
log.info("GeneDTOConsumer Starting:" + threadCount); | ||
context = connectionFactory1.createContext(Session.AUTO_ACKNOWLEDGE); | ||
producer = context.createProducer(); | ||
for(int i = 0; i < threadCount; i++) { | ||
scheduler.scheduleWithFixedDelay(new Thread(this), 0L, 5L, TimeUnit.SECONDS); | ||
} | ||
} | ||
|
||
void onStop(@Observes ShutdownEvent ev) { | ||
log.info("Shutdown"); | ||
scheduler.shutdown(); | ||
context.close(); | ||
} | ||
|
||
@Override @ActivateRequestContext | ||
public void run() { | ||
JMSContext ctx = null; | ||
try { | ||
ctx = connectionFactory2.createContext(Session.AUTO_ACKNOWLEDGE); | ||
JMSConsumer consumer = ctx.createConsumer(ctx.createQueue("geneQueue")); | ||
while (true) { | ||
geneService.processUpdate(consumer.receiveBody(GeneDTO.class)); | ||
} | ||
} catch (Exception e) { | ||
if(ctx != null) ctx.close(); | ||
log.info("Thread process failed: Error: " + e); | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public void send(GeneDTO gene) { | ||
producer.send(context.createQueue("geneQueue"), context.createObjectMessage(gene)); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/alliancegenome/curation_api/main/Main.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,14 @@ | ||
package org.alliancegenome.curation_api.main; | ||
|
||
import io.quarkus.runtime.Quarkus; | ||
import io.quarkus.runtime.annotations.QuarkusMain; | ||
|
||
@QuarkusMain | ||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Running main method of quarkus"); | ||
Quarkus.run(args); | ||
} | ||
|
||
} |
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