Java Code Examples for akka.stream.ActorMaterializer#create()
The following examples show how to use
akka.stream.ActorMaterializer#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AkkaHttpClientITest.java From java-specialagent with Apache License 2.0 | 6 votes |
public static void main(final String[] args) throws Exception { final ActorSystem system = ActorSystem.create(); final Materializer materializer = ActorMaterializer.create(system); final Http http = getHttp(system); final CompletionStage<HttpResponse> stage = http.singleRequest(HttpRequest.GET("http://www.google.com")); stage.whenComplete(new BiConsumer<HttpResponse,Throwable>() { @Override public void accept(final HttpResponse httpResponse, final Throwable throwable) { TestUtil.checkActiveSpan(); System.out.println(httpResponse.status()); } }).toCompletableFuture().get().entity().getDataBytes().runForeach(param -> {}, materializer); stage.thenRun(system::terminate).toCompletableFuture().get(); TestUtil.checkSpan(new ComponentSpanCount("akka-http-client", 1)); }
Example 2
Source File: ReconnectActor.java From ditto with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("unused") private ReconnectActor(final ActorRef connectionShardRegion, final Supplier<Source<String, NotUsed>> currentPersistenceIdsSourceSupplier) { this.connectionShardRegion = connectionShardRegion; this.currentPersistenceIdsSourceSupplier = currentPersistenceIdsSourceSupplier; reconnectConfig = getReconnectConfig(getContext()); materializer = ActorMaterializer.create(getContext()); }
Example 3
Source File: DefaultHttpClientFacade.java From ditto with Eclipse Public License 2.0 | 5 votes |
private static DefaultHttpClientFacade createInstance(final ActorSystem actorSystem, final HttpProxyConfig proxyConfig) { ConnectionPoolSettings connectionPoolSettings = ConnectionPoolSettings.create(actorSystem); if (proxyConfig.isEnabled()) { connectionPoolSettings = connectionPoolSettings.withTransport(proxyConfig.toClientTransport()); } return new DefaultHttpClientFacade(actorSystem, ActorMaterializer.create(actorSystem), connectionPoolSettings); }
Example 4
Source File: SimpleClusterMain.java From akka-kubernetes-example with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { ActorSystem actorSystem = ActorSystem.create(CLUSTER_NAME); actorSystem.actorOf(SimpleClusterListener.props()); final ActorMaterializer materializer = ActorMaterializer.create(actorSystem); Cluster cluster = Cluster.get(actorSystem); List<Address> addresses = Arrays.asList(System.getenv().get("SEED_NODES").split(",")) .stream() .map(ip -> new Address("akka.tcp", CLUSTER_NAME, ip, 2551)) .collect(Collectors.toList()); cluster.joinSeedNodes(addresses); }
Example 5
Source File: KafkaSagaEventConsumer.java From servicecomb-pack with Apache License 2.0 | 5 votes |
public KafkaSagaEventConsumer(ActorSystem actorSystem, ActorRef sagaShardRegionActor, MetricsService metricsService, String bootstrap_servers, String topic) { super(actorSystem, sagaShardRegionActor, metricsService); // init consumer final Materializer materializer = ActorMaterializer.create(actorSystem); final Config consumerConfig = actorSystem.settings().config().getConfig("akka.kafka.consumer"); final ConsumerSettings<String, String> consumerSettings = ConsumerSettings .create(consumerConfig, new StringDeserializer(), new StringDeserializer()) .withBootstrapServers(bootstrap_servers) .withGroupId(groupId) .withProperty(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false") .withProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest") .withProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "StringDeserializer.class") .withProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "StringDeserializer.class"); Consumer.committableSource(consumerSettings, Subscriptions.topics(topic)) .mapAsync(20, event -> { BaseEvent bean = jsonMapper.readValue(event.record().value(), BaseEvent.class); if (LOG.isDebugEnabled()) { LOG.debug("receive [{}] {} {}", bean.getGlobalTxId(), bean.getType(), bean.getLocalTxId()); } return sendSagaActor(bean).thenApply(done -> event.committableOffset()); }) .batch( 100, ConsumerMessage::createCommittableOffsetBatch, ConsumerMessage.CommittableOffsetBatch::updated ) .mapAsync(20, offset -> offset.commitJavadsl()) .to(Sink.ignore()) .run(materializer); }
Example 6
Source File: StreamIT.java From reactive-stock-trader with Apache License 2.0 | 5 votes |
@BeforeClass public static void setup() { clientFactory = LagomClientFactory.create("integration-test", StreamIT.class.getClassLoader()); // One of the clients can use the service locator, the other can use the service gateway, to test them both. system = ActorSystem.create(); mat = ActorMaterializer.create(system); }
Example 7
Source File: ThingsJournalTestHelper.java From ditto with Eclipse Public License 2.0 | 5 votes |
/** * Constructor. * * @param actorSystem the actor system to be used to find the persistence extension * @param journalEntryToDomainObject a {@link BiFunction} providing the journal entry and its sequence number and * expecting a domain object * @param domainIdToPersistenceId a {@link Function} providing the domain ID and expecting the matching * persistence ID */ public ThingsJournalTestHelper(final ActorSystem actorSystem, final BiFunction<BsonDocument, Long, J> journalEntryToDomainObject, final Function<ThingId, String> domainIdToPersistenceId) { this.journalEntryToDomainObject = requireNonNull(journalEntryToDomainObject); this.domainIdToPersistenceId = requireNonNull(domainIdToPersistenceId); mat = ActorMaterializer.create(actorSystem); readJournal = PersistenceQuery.get(actorSystem). getReadJournalFor(InMemoryReadJournal.class, InMemoryReadJournal.Identifier()); }
Example 8
Source File: ThingsAggregatorActor.java From ditto with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("unused") private ThingsAggregatorActor(final ActorRef targetActor) { this.targetActor = targetActor; aggregatorDispatcher = getContext().system().dispatchers().lookup(AGGREGATOR_INTERNAL_DISPATCHER); final ThingsAggregatorConfig aggregatorConfig = DittoConciergeConfig.of( DefaultScopedConfig.dittoScoped(getContext().getSystem().settings().config()) ).getThingsAggregatorConfig(); retrieveSingleThingTimeout = aggregatorConfig.getSingleRetrieveThingTimeout(); maxParallelism = aggregatorConfig.getMaxParallelism(); actorMaterializer = ActorMaterializer.create(getContext()); }
Example 9
Source File: MongoReadJournalIT.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Before public void setUp() { // set persistence plugin Mongo URI for JavaDslReadJournal test final String mongoUri = String.format("mongodb://%s:%d/%s", MONGO_HOST, mongoResource.getPort(), MONGO_DB); final Config config = ConfigFactory.load("mongo-read-journal-test") .withValue("akka.contrib.persistence.mongodb.mongo.mongouri", ConfigValueFactory.fromAnyRef(mongoUri)); actorSystem = ActorSystem.create("AkkaTestSystem", config); materializer = ActorMaterializer.create(actorSystem); readJournal = MongoReadJournal.newInstance(config, mongoClient); }
Example 10
Source File: ResultConsumer.java From kafka-tutorials with Apache License 2.0 | 5 votes |
public static void main(String[] args) { final Config config = ConfigFactory.load(); final String outputTopic = config.getString("output.topic.name"); final ActorSystem system = ActorSystem.create(); final Materializer materializer = ActorMaterializer.create(system); final ConsumerSettings<Windowed<String>, Long> consumerSettings = ConsumerSettings .create( system, timeWindowedSerdeFrom( String.class, config.getDuration("window.size").toMillis() ).deserializer(), Serdes.Long().deserializer() ) .withGroupId(UUID.randomUUID().toString()) .withBootstrapServers(config.getString("bootstrap.servers")) .withProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); Consumer.plainSource( consumerSettings, Subscriptions.topics(outputTopic)) .to(Sink.foreach((record) -> { logger.info(printWindowedKey(config, record)); return BoxedUnit.UNIT; }) ).run(materializer); }
Example 11
Source File: WebsocketMessageToProducerRecordTranslator.java From ari-proxy with GNU Affero General Public License v3.0 | 5 votes |
private static ActorMaterializer run(ActorSystem system, ActorRef callContextProvider, ActorRef metricsService, Source<Message, NotUsed> source, Sink<ProducerRecord<String, String>, NotUsed> sink, Runnable applicationReplacedHandler) { final Function<Throwable, Supervision.Directive> supervisorStrategy = t -> { system.log().error(t, t.getMessage()); return Supervision.resume(); }; final Config kafkaConfig = ConfigFactory.load().getConfig(SERVICE).getConfig(KAFKA); final String commandsTopic = kafkaConfig.getString(COMMANDS_TOPIC); final String eventsAndResponsesTopic = kafkaConfig.getString(EVENTS_AND_RESPONSES_TOPIC); final ActorMaterializer materializer = ActorMaterializer.create( ActorMaterializerSettings.create(system).withSupervisionStrategy(supervisorStrategy), system); source //.throttle(4 * 13, Duration.ofSeconds(1)) // Note: We die right now for calls/s >= 4.8 .wireTap(Sink.foreach(msg -> gatherMetrics(msg, metricsService, callContextProvider))) .flatMapConcat((msg) -> generateProducerRecordFromEvent(commandsTopic, eventsAndResponsesTopic, msg, callContextProvider, system.log(), applicationReplacedHandler)) .log(">>> ARI EVENT", record -> record.value()).withAttributes(LOG_LEVELS) .to(sink) .run(materializer); return materializer; }
Example 12
Source File: AbstractBackgroundStreamingActorWithConfigWithStatusReport.java From ditto with Eclipse Public License 2.0 | 5 votes |
/** * Initialize the actor with a background streaming config. * * @param config the background streaming config. */ protected AbstractBackgroundStreamingActorWithConfigWithStatusReport(final C config) { this.config = config; log = DittoLoggerFactory.getDiagnosticLoggingAdapter(this); materializer = ActorMaterializer.create(getContext()); events = new ArrayDeque<>(config.getKeptEvents() + 1); if (config.isEnabled()) { scheduleWakeUp(); } }
Example 13
Source File: MongoTimestampPersistenceIT.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Before public void setUp() { final Config config = ConfigFactory.load("test"); actorSystem = ActorSystem.create("AkkaTestSystem", config); materializer = ActorMaterializer.create(actorSystem); syncPersistence = MongoTimestampPersistence.initializedInstance(KNOWN_COLLECTION, mongoClient, materializer); }
Example 14
Source File: ReconnectActor.java From ditto with Eclipse Public License 2.0 | 5 votes |
@SuppressWarnings("unused") private ReconnectActor(final ActorRef connectionShardRegion, final MongoReadJournal readJournal) { this.connectionShardRegion = connectionShardRegion; reconnectConfig = getReconnectConfig(getContext()); materializer = ActorMaterializer.create(getContext()); currentPersistenceIdsSourceSupplier = () -> readJournal.getJournalPids(reconnectConfig.getReadJournalBatchSize(), reconnectConfig.getInterval(), materializer); }
Example 15
Source File: SearchActorIT.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Before public void before() { actorSystem = ActorSystem.create(getClass().getSimpleName(), ConfigFactory.parseString("search-dispatcher {\n" + " type = PinnedDispatcher\n" + " executor = \"thread-pool-executor\"\n" + "}")); materializer = ActorMaterializer.create(actorSystem); readPersistence = provideReadPersistence(); writePersistence = provideWritePersistence(); thingsCollection = mongoClient.getDefaultDatabase().getCollection(PersistenceConstants.THINGS_COLLECTION_NAME); }
Example 16
Source File: ResumeSourceTest.java From ditto with Eclipse Public License 2.0 | 5 votes |
@Before public void init() { system = ActorSystem.create(); mat = ActorMaterializer.create(system); rematerializeSource(); // materialize sink once - it never fails. final Sink<Integer, TestSubscriber.Probe<Integer>> sink = TestSink.probe(system); final Pair<TestSubscriber.Probe<Integer>, Sink<Integer, NotUsed>> sinkPair = sink.preMaterialize(mat); sinkProbe = sinkPair.first(); testSink = sinkPair.second(); }
Example 17
Source File: ThingsAggregatorProxyActor.java From ditto with Eclipse Public License 2.0 | 4 votes |
@SuppressWarnings("unused") private ThingsAggregatorProxyActor(final ActorRef targetActor) { this.targetActor = targetActor; actorMaterializer = ActorMaterializer.create(getContext()); }
Example 18
Source File: DefaultPersistenceStreamingActorTest.java From ditto with Eclipse Public License 2.0 | 4 votes |
private ActorMaterializer materializer() { return ActorMaterializer.create(actorSystem); }
Example 19
Source File: MergeSortedAsPairTest.java From ditto with Eclipse Public License 2.0 | 4 votes |
@BeforeClass public static void init() { system = ActorSystem.create(); mat = ActorMaterializer.create(system); }
Example 20
Source File: AmqpConnectorsTest.java From rabbitmq-mock with Apache License 2.0 | 4 votes |
@BeforeAll public static void setUp() { system = ActorSystem.create(); materializer = ActorMaterializer.create(system); }