public void Init() { string connStr = CreateConnectString(); RabbitBus = RabbitHutch.CreateBus(connStr); RabbitBus.Receive <T>(Options.Queue, new Action <T>(Consuming)); }
/// <summary> /// Ten kod wykonuje się przy naciśnięciu X /// Wysyłamy do Rabbita informacje o wyjściu, aby usunąć naszą ikonkę z mapy /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CloseApp(object sender, CancelEventArgs e) { InfoOfMe.UserInfo.IsLeaving = true; InfoOfMe.UserInfo.IsNew = false; InfoOfMe.UserInfo.IsUpdated = false; NetworkingHandler.Publisher.Publish(InfoOfMe.UserInfo); RabbitBus.Dispose(); AfkTimer.Dispose(); }
public async Task PublishAsync(T message) { if (message == null) { return; } await RabbitBus.SendAsync(Options.Queue, message); }
public void Publish(T message) { if (message == null) { return; } RabbitBus.Send(Options.Queue, message); }
private void CreateBus(Conventions conventions, IModel model) { bus = new RabbitBus( x => TypeNameSerializer.Serialize(x.GetType()), new JsonSerializer(), new MockConsumerFactory(), new MockConnectionFactory(new MockConnection(model)), new MockLogger(), CorrelationIdGenerator.GetCorrelationId, conventions ); }
public static void ChatJoinedHandler(RabbitBus bus) { var messages = bus.Message <ChatUserJoined>().GetAll(); Console.WriteLine($"[*System] {messages.Length} users joined in the meantime"); bus.Message <ChatUserJoined>().Subscribe(wrapper => { var payload = wrapper.Payload; var adminText = payload.IsAdmin ? "*" : string.Empty; Console.WriteLine($"[{adminText}{payload.Name}] joined"); return(Task.FromResult(HandleResult.Ok)); }, SubscriptionType.SharedBetweenConsumers); }
static void Main(string[] args) { Console.WriteLine(" ###############################"); Console.WriteLine(" # RabbitMQ Client 2 (user) #"); Console.WriteLine(" ###############################"); Console.WriteLine(); var config = RabbitValues.CONFIG; config.ConsumerName = "user"; var random = new Random(DateTime.Now.Millisecond); var userId = random.Next(2, 99); var user = new ChatUserPayload() { Id = userId, IsAdmin = false, Name = "User " + userId }; Console.WriteLine($"Logged in as {user.Name}"); Console.WriteLine(); using (var bus = new RabbitBus(NullLogger <IBus> .Instance, new OptionsWrapper <BusConfig>(config))) { bus.Init(); RabbitValues.ChatHandler(bus); bus.Message <ChatUserJoined>().Publish(user); while (true) { var msg = Console.ReadLine(); RabbitValues.DeletePrevConsoleLine(); bus.Message <ChatMessageInserted>().Publish(new ChatMessagePayload() { User = user, IsProtected = msg == "secret", Plaintext = msg }); } } }
public static void ChatHandler(RabbitBus bus) { bus.Message <ChatMessageInserted>().Subscribe(wrapper => { var payload = wrapper.Payload; if (payload.IsProtected) { Console.WriteLine($"[{payload.User.Name}] > *** protected ***"); } else { Console.WriteLine($"[{payload.User.Name}] > {payload.Plaintext}"); } return(Task.FromResult(HandleResult.Ok)); }, SubscriptionType.PerConsumer); }
static void Main(string[] args) { Console.WriteLine(" ###############################"); Console.WriteLine(" # RabbitMQ Client 1 (admin) #"); Console.WriteLine(" ###############################"); Console.WriteLine(); var config = RabbitValues.CONFIG; config.ConsumerName = "admin"; var user = new ChatUserPayload() { Id = 1, IsAdmin = true, Name = "System Admin" }; Console.WriteLine($"Logged in as {user.Name}"); Console.WriteLine(); using (var bus = new RabbitBus(NullLogger <IBus> .Instance, new OptionsWrapper <BusConfig>(config))) { bus.Init(); RabbitValues.ChatJoinedHandler(bus); RabbitValues.ChatHandler(bus); bus.Message <ChatUserJoined>().Publish(user); while (true) { var msg = Console.ReadLine(); RabbitValues.DeletePrevConsoleLine(); bus.Message <ChatMessageInserted>().Publish(new ChatMessagePayload() { User = user, IsProtected = msg == "secret", Plaintext = msg }); } } }
private void CreateBus(IConventions conventions, IModel model) { var advancedBus = new RabbitAdvancedBus( new ConnectionConfiguration(), new MockConnectionFactory(new MockConnection(model)), TypeNameSerializer.Serialize, new JsonSerializer(), new MockConsumerFactory(), new MockLogger(), CorrelationIdGenerator.GetCorrelationId, new Conventions() ); bus = new RabbitBus( x => TypeNameSerializer.Serialize(x.GetType()), new MockLogger(), conventions, advancedBus ); }
/// <summary> /// Logika przycisku "Connect" /// Funkcja odpowiadająca za łączenie z wysyłaniem i odbieraniem z Rabbita. /// Dodatkowa logika związana z rozłączeniem się i wyłączeniem apki /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ClickConnect(object sender, RoutedEventArgs e) { if (!IsConnected) { if (!CheckConditions()) { return; } if (!IsAnimalPinPlaced) { MessageBox.Show("Pin not placed. Please place a pin on a map before connecting. To place a pin, double click a point on the map.", "Pin not found!", MessageBoxButton.OK, MessageBoxImage.Error); return; } usernameBox.IsEnabled = false; typeBox.IsEnabled = false; IsConnected = true; Publisher.Publish(InfoOfMe.UserInfo); Subscriber.Subscribe(); connButton.Content = "Disconnect"; AfkTimer = new System.Threading.Timer(tmr => HandleAFKs.DeleteAfks(), null, TimeSpan.Zero, TimeSpan.FromMinutes(5)); } else { if (MessageBox.Show("Do you really want to disconnect and exit?", "Should I?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { InfoOfMe.UserInfo.IsLeaving = true; InfoOfMe.UserInfo.IsNew = false; InfoOfMe.UserInfo.IsUpdated = false; Publisher.Publish(InfoOfMe.UserInfo); RabbitBus.Dispose(); connButton.Content = "Connect"; System.Windows.Application.Current.Shutdown(); } } }
private void CreateBus(Conventions conventions, IModel model) { var advancedBus = new RabbitAdvancedBus( new ConnectionConfiguration(), new MockConnectionFactory(new MockConnection(model)), TypeNameSerializer.Serialize, new JsonSerializer(), new MockConsumerFactory(), new MockLogger(), CorrelationIdGenerator.GetCorrelationId, conventions, new DefaultMessageValidationStrategy(new MockLogger(), TypeNameSerializer.Serialize)); bus = new RabbitBus( x => TypeNameSerializer.Serialize(x.GetType()), new MockLogger(), conventions, advancedBus ); }
public void Initialize() { _mockBusControl = new Mock<IBusControl>(); _bus = new RabbitBus(_mockBusControl.Object); }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container /// </summary> /// <param name="services"></param> public void ConfigureServices(IServiceCollection services) { services .AddDbContext <MentifiContext>(options => options.UseSqlServer(Configuration.GetConnectionString("Hub3cConnection"))).AddUnitOfWork <MentifiContext>(); services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) .AddIdentityServerAuthentication(options => { options.Authority = Configuration["AuthUrl"]; options.RequireHttpsMetadata = false; }); services.AddScoped <IDeserializer, JsonDeserializer>(); services.AddScoped <IUserProfileService, UserProfileService>(); services.AddScoped <IApiClient, ApiClient>(); services.AddScoped <IConnectionService, ConnectionService>(); services.AddScoped <ILookupService, LookupService>(); services.AddScoped <ISystemUserDeviceService, SystemUserDeviceService>(); services.AddScoped <IHub3cFirebaseApi, Hub3CFirebaseApi>(); services.AddScoped <IDashboardService, DashboardService>(); services.AddScoped <INotificationService, NotificationService>(); services.AddScoped <IEmailApi, EmailApi>(); services.AddScoped <IBulletinService, BulletinService>(); services.AddScoped <IDocumentService, DocumentService>(); services.AddScoped <IBusInstance, BusInstance>(); services.AddScoped <IGoalService, GoalService>(); services.AddScoped <IGoalProgressService, GoalProgressService>(); services.AddScoped <ITaskService, TaskService>(); services.AddScoped <IMessageBoardService, MessageBoardService>(); services.AddScoped <IMessageService, MessageService>(); services.AddScoped <IProjectService, ProjectService>(); services.AddScoped <IProjectTeamService, ProjectTeamService>(); services.AddScoped <IAdminInvitationService, AdminInvitationService>(); services.AddScoped <IInvitationLinkService, InvitationLinkService>(); services.AddScoped <IExperienceService, ExperienceService>(); services.AddScoped <IInformalExperienceService, InformalExperienceService>(); services.AddScoped <ISubjectExperienceService, SubjectExperienceService>(); services.AddScoped <ISubjectPreferenceService, SubjectPreferenceService>(); services.AddScoped <IAdditionalActivityService, AdditionalActivityService>(); services.AddScoped <IUserAddressService, UserAddressService>(); services.AddScoped <IEducationService, EducationService>(); var mongoOpt = Configuration.GetSection("MongoDbConfig"); services.AddSingleton <IMongoClient>(new MongoClient(mongoOpt.GetSection("Host").Value)); services.AddSingleton <IMongoRepository <Resource>, MongoRepository <Resource> >(); // For Rabbit Subscriber var rabbitUsername = Configuration.GetSection("MessagingConfig")["RabbitUsername"]; var rabbitPassword = Configuration.GetSection("MessagingConfig")["RabbitPassword"]; var rabbitHost = Configuration.GetSection("MessagingConfig")["RabbitServer"]; var rabbitVHost = Configuration.GetSection("MessagingConfig")["RabbitVHost"]; var subscriber = new RabbitSubscriber(rabbitUsername, rabbitPassword, rabbitHost, rabbitVHost); var rabbitBus = new RabbitBus(rabbitHost, rabbitUsername, rabbitPassword, rabbitVHost); var busInstance = new BusInstance(rabbitBus); services.AddSingleton(subscriber); services.AddSingleton(rabbitBus); services.AddSingleton(busInstance); services.AddMvc(op => { op.Filters.Add(new ValidateModelStateAttribute()); }); // Register the Swagger generator, defining one or more Swagger documents services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Mentify API", Version = "v1" }); c.SwaggerDoc("v2", new Info { Title = "Mentify API", Version = "v2" }); c.DocInclusionPredicate((version, apiDesc) => { var versions = apiDesc.ControllerAttributes() .OfType <ApiVersionAttribute>() .SelectMany(attr => attr.Versions); var values = apiDesc.RelativePath .Split('/'); values[1] = version; apiDesc.RelativePath = string.Join("/", values); var versionParameter = apiDesc.ParameterDescriptions .SingleOrDefault(p => p.Name == "version"); if (versionParameter != null) { apiDesc.ParameterDescriptions.Remove(versionParameter); } //return true; return(versions.Any(v => $"v{v.ToString()}" == version)); }); c.AddSecurityDefinition("Bearer", new ApiKeyScheme { In = "header", Description = "Please insert JWT with Bearer into field", Name = "Authorization", Type = "apiKey", }); c.IncludeXmlComments(GetXmlCommentsPath()); c.DescribeAllEnumsAsStrings(); c.DescribeAllParametersInCamelCase(); }); services.AddCors(); services.AddApiVersioning( o => { o.AssumeDefaultVersionWhenUnspecified = true; o.DefaultApiVersion = new ApiVersion(new DateTime(2018, 2, 6), 1, 0); }); }
public virtual void Dispose() { RabbitBus.Dispose(); RabbitBus = null; }